Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-update

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-update

update for deep nested object

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

object-update

Update a deep nested object with path, return the origin object if not change.

Installation

Just use npm to install it. If you want to use it in frontend, use can use webpack or browserify to bundle it to your codebase

npm install object-update

How to use

var update = require('object-update')
var obj = {
  foo: 'bar',
  nest: {
    cat: 'moew'
  },
  arr: [ 0, 1, 2 ]
}

var newObject = update(obj, {
  'foo': 'barrr',
  'arr.1': 100, // support array
  'nest.cat': { kitty: 'lol' }
})

console.log(newObject)
// {
//   foo: 'barrr',
//   nest: {
//     cat: { kitty: 'lol' }
//   },
//   arr: [ 0, 100, 2 ]
// }
//

It is very appreciate to do PureRender if you are using React.js like this:

{
  handleClick () {
    const newObj = update(this.state.todos, {
      '1.text': 'new text'
    })

    this.setState(newObj)
  }

  shouldComponentUpdate (nextProps, nextState) {
    // pure render
    return !shallowEqual(this.props, nextProps) ||
           !shallowEqual(this.state, nextState)
  }
}

For more use case, check the lnode.spec.js in test folder.

Keywords

FAQs

Package last updated on 09 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc