Nature's Powerful Meme

    object-end-keys

    3.0.1 • Public • Published

    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

    Install

    npm i object-end-keys

    DownloadsWeekly Downloads

    373

    Version

    3.0.1

    License

    MIT

    Last publish

    Collaborators

    • padurets