get all end keys of object
Clone or download
Pull request Compare This branch is 17 commits ahead, 13 commits behind coderaiser:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
ChangeLog
LICENSE
README.md
package.json

README.md

object-end-keys

Build Status Coverage Status

Install

npm i object-end-keys -S

Default options

var options = {
    separator: '.',
    keyType: {
        string: {
            prefix: '',
            suffix: ''
        },
        number: {
            prefix: '[',
            suffix: ']'
        }
    }
};

Usage example

var keys = require('object-end-keys');
var data = {
    "name": {
        "first": "Joseph",
        "last": "Raketov"
    },
    "age": 24,
    "eyeColor": "red",
    "friends": [
      {
        "id": 0,
        "name": "Alex Shakirov"
      }
    ]
};
Example 1: simple
keys(obj)
// ["name.first", "name.last", "age", "eyeColor", "friends[0].id", "friends[0].name"]
Example 2: includeParent
options = {
    includeParent: true
}

keys(obj, options)
// ["name", "name.first", "name.last", "age", "eyeColor", "friends", "friends[0]", "friends[0].id", "friends[0].name"]
Example 3: prefix/suffix of keyType
options = {
    keyType: {
        number: {
            prefix: '.',
            suffix: ''
        }
    }
};

keys(obj, options)
// ["name.first", "name.last", "age", "eyeColor", "friends.0.id", "friends.0.name"]

TODO:

  • support for browsers