Skip to content

Latest commit

 

History

History
76 lines (67 loc) · 1.5 KB

README.md

File metadata and controls

76 lines (67 loc) · 1.5 KB

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