Skip to content

πŸ—„ Get, set, or remove a property from a nested object using a separator of your choosing

License

Notifications You must be signed in to change notification settings

trashify/sep-prop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—„ sep-prop

Get, set, or remove a property from a nested object using a separator of your choosing



Built with ❀︎ by Tiaan and contributors

Table of Contents

Table of Contents
  • About
  • Install
  • Usage
  • API
  • Contribute
  • License
  • About

    Based and inspired by dot-prop. Allows you to get, set, or remove a property from a nested object using a separator of your choosing. Support for escaping.

    Install

    $ npm install --save sep-prop

    Or

    $ yarn add sep-prop

    Usage

    const prop = require('sep-prop')
    
    const obj = {
      foo: {
        bar: {
          baz: 5
        },
        'oof/bax': {
          rab: 'zab'
        }
      }
    }
    
    console.log(prop.get(obj, 'foo/bar')) // {baz: 5}
    console.log(prop.get(obj, 'foo$$bar', {sep: '$$'}))  // {baz: 5}
    console.log(prop.get(obj, 'foo.bar', {sep: '.'}))
    console.log(prop.get(obj, 'foo/oof$$/bax', {escape: '$$'})) // {rab: 'zab'}
    
    console.log(prop.set(obj, 'foo/bar', 'Hi')) //{ foo: { bar: 'Hi', 'oof/bax': { rab: 'zab' } } }
    console.log(prop.set(obj, 'foo/bar/baz', 5)) //{ foo: { bar: { baz: 5 }, 'oof/bax': { rab: 'zab' } } }
    
    console.log(prop.remove(obj, 'foo/bar')) // true
    console.log(obj) // { foo: { 'oof/bax': { rab: 'zab' } } }

    API

    get

    Retrieve nested property from object.

    Parameters

    set

    Set a property on a object.

    Parameters

    remove

    Remove property from object.

    Parameters

    Contribute

    Contributions are welcome. Please open up an issue or create PR if you would like to help out.

    Note: If editing the README, please conform to the standard-readme specification.

    License

    Licensed under the MIT License.

    About

    πŸ—„ Get, set, or remove a property from a nested object using a separator of your choosing

    Topics

    Resources

    License

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published