Skip to content

Conversation

@padurets
Copy link

@padurets padurets commented Dec 22, 2016

it is now possible to set prefixes and suffixes for indexes. Leads to the mind:

const keys = require('all-object-keys');

var options = {
    iPrefix: '[',
    iSuffix: ']'
};

var obj =  {
    universal: true,
    hello: {
        world: {
            x: 'could be used in browser as well'
        }
    },
    array: ['a','b', {c: 'e'}]
};

keys(options, obj)
// returns
// ["universal", "hello.world.x", "array[0]", "array[1]", "array[2].c"]

keys(obj)
// returns
// ["universal", "hello.world.x", "array.0", "array.1", "array.2.c"]

@coderaiser
Copy link
Owner

Why you need this feature?

@padurets
Copy link
Author

padurets commented Dec 22, 2016

to format lodash.get

var lodashGet = require('lodash.get');
var object = { 'a': [{ 'b': { 'c': 3 } }] };
 
lodashGet(object, 'a[0].b.c');
// => 3

@coveralls
Copy link

coveralls commented Dec 22, 2016

Coverage Status

Coverage decreased (-6.5%) to 93.548% when pulling f4a7d98 on padurets:master into acd8994 on coderaiser:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-6.5%) to 93.548% when pulling 97cc3f9 on padurets:master into acd8994 on coderaiser:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-6.5%) to 93.548% when pulling 97cc3f9 on padurets:master into acd8994 on coderaiser:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-6.5%) to 93.548% when pulling 97cc3f9 on padurets:master into acd8994 on coderaiser:master.

@padurets padurets changed the title v2.1.0 v2.2.0 Dec 22, 2016
@coderaiser
Copy link
Owner

coderaiser commented Dec 22, 2016

You can do the same things using jessy already:

const obj =  {
    array: ['a','b', {c: 'e'}]
};

const keys = allObjectKeys(obj);
// returns
["array.0", "array.1", "array.2.c"]

jessy('array.2.c', obj);
// returns
"e"

@padurets
Copy link
Author

in another package used lodash, I need the functionality of your module with the ability to change the prefixes. So I decided to pull request, instead of doing a separate package. Do you think is better to make this functionality requirements, based on a new package?

@coderaiser
Copy link
Owner

Yes, I think you better fork all-object-keys to make something that will fit your needs more.

@coderaiser coderaiser closed this Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants