Comments (15)
I pushed up a branch with support for array-notation, but I haven't made up my mind on whether or not to support it, since it has a slight impact on performance.
how were you thinking of using this feature? what use case? It might help me decide. thanks!
from get-value.
I'm converting these to JSON in leesei/openslide-prop2json
.
openslide.level[0].downsample: '1'
openslide.level[0].height: '32893'
openslide.level[0].tile-height: '240'
openslide.level[0].tile-width: '240'
openslide.level[0].width: '46000'
openslide.level[1].downsample: '4.0000608050589808'
openslide.level[1].height: '8223'
openslide.level[1].tile-height: '240'
openslide.level[1].tile-width: '240'
openslide.level[1].width: '11500'
openslide.level[2].downsample: '16.003163017031632'
openslide.level[2].height: '2055'
openslide.level[2].tile-height: '240'
openslide.level[2].tile-width: '240'
openslide.level[2].width: '2875'
My current implementation also does not convert them to array.
Also, we must use array notation for hyphenated keys: object['foo-bar']: 3
.
Did you have the performance test set up?
I would like to try this:
var segs = prop.split(/[.\[\]]/).filter(function (s) { return s; });
from get-value.
Did you have the performance test set up?
yes, if you git clone then do npm install -D
, then run node benchmark
, you can see how changes effect the speed.
however... the regex you mentioned won't work since ].
is two characters. You'll need to add +
after the last bracket, like: /[.\[\]]+/
.
see https://github.com/jonschlinkert/get-value/blob/array-notation/index.js#L26
from get-value.
I'm guessing that the or(|
) in your regex causes backtracking.
I'm splitting ]
and .
(excessively) so I have to filter the empty segment.
I can try different regex and compare the performance. Thanks for the great work.
I'll get back to you.
from get-value.
no worries, thanks
from get-value.
http://jsperf.com/get-value-array-notation
Alas, I'm ashamed to put the "split and filter" code up, it only have 23000 ops.
Feel free to edit the test.
from get-value.
The performance was decreased with this added feature by more than 50%. I also hesitate to merge it to master.
I suggest adding an option for this use case.
var get = require('get-value')({arrayNotation: true});
index.js
would export closure that set a SPLIT_SEPERATOR
variable and return the current implementation with this modification:
var segs = prop.split(SPLIT_SEPERATOR);
from get-value.
Or we can allow user to pass the separator to support more use cases.
var GetValue = require('get-value');
var get1 = GetValue({separator: GetValue.DOT_ONLY}); // default
var get2 = GetValue({separator: GetValue.SUPPORT_ARRAY_NOTATION});
var get3 = GetValue({separator: '_'}); // custom separator
from get-value.
suggest adding an option for this use case.
Hmm, maybe we can take a function as the third argument, which would be expected to return an array of property paths.
thoughts?
from get-value.
That's great.
It provides the same feature without having to export a constructor function.
const get = require('get-value');
const obj = { e: [ {f : 'g'} ] };
// default tokenizer using '.'
// trying to access `obj['e[0]']`
console.log(get(obj, 'e[0].f')); // undefined
// custom tokenizer
// take cares of array notation
console.log(get(obj, 'e[0].f', (prop) => prop.split(/(?:\.|\[|\]\.)/)); // 'g'
from get-value.
Tangential to this issue
I suggest a, b, c
to be removed, see #5
from get-value.
Now that the a, b, c
params are kept, how should the function be added?
One way is to switch between the two features:
if (typeof a === 'function') {
tokenizer = a;
} else {
// allowing for multiple properties to be passed as
// a string or array, but much faster (3-4x) than doing
// `[].slice.call(arguments)`
if (a) prop += '.' + toString(a);
if (b) prop += '.' + toString(b);
if (c) prop += '.' + toString(c);
}
from get-value.
Closing since this was implemented a while ago.
from get-value.
@jonschlinkert Could you please give an example? I tried split and separator
options but cannot make it work. Thanks.
from get-value.
The README.md has an example for how to use the split
option. If that doesn't work, please open an issue with an example of the code your are trying.
from get-value.
Related Issues (19)
- Benchmark against object-path HOT 2
- Unexpected Identifier and WebpackJsonp not defined on building Android in Ionic HOT 1
- Please pre-compiled before publish HOT 2
- Issue with Default Value of 0 HOT 2
- default value is useless without isValid call, which defaults to true for everything HOT 2
- benckmark compare with object.get HOT 1
- document escaping dot HOT 1
- how to get a path of a key? HOT 2
- Question - any significant differences between this library and lodash's _.get() ? HOT 1
- benchmark optional chaining HOT 1
- update dep
- missing index.d.ts
- collection not accessible HOT 2
- Benchmark result HOT 7
- docs: mention support for passing an array for `key`
- Using array notation breaks when values has periods HOT 7
- Open to PR with `get(...default='default')`? HOT 2
- npmjs package does not include readme HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from get-value.