New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nested-props

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nested-props

Define nested properties value

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

nested-props

This package is an utils to help you define nested properties and values deep inside a javascript object. See example below.

Install

npm install nested-props --save

Example

var nested = require('nested-props')

var obj = {
  coordinates: [{
    value: [11, 22]
  }, {
    value: [33, 44, 55]
  }]
}
nested.set(obj, 'user.name', 'username')
nested.set(obj, 'user.id', '666')
nested.set(obj, 'user.info.city', 'paris')
nested.set(obj, 'user.info.country', 'france')
/*
{ coordinates: [ { value: [Object] }, { value: [Object] } ],
  user:
   { name: 'username',
     id: '666',
     info: { city: 'paris', country: 'france' } } }
*/

nested.set(obj, 'user.id.value', '666')
/*
{ coordinates: [ { value: [Object] }, { value: [Object] } ],
  user:
   { name: 'username',
     id: { value: '666' },
     info: { city: 'paris', country: 'france' } } }
*/

nested.set(obj, 'user.id.value', '777')
/*
{ coordinates: [ { value: [Object] }, { value: [Object] } ],
  user:
   { name: 'username',
     id: { value: '777' },
     info: { city: 'paris', country: 'france' } } }
*/

var country = nested.get(obj, 'user.info.country')
/*
  france
*/

/* use this method to prevent : TypeError: Cannot read property 'test' of undefined */
var undefinedTest = nested.get(obj, 'user.test.test')
/*
  undefined
*/


var coordinate1 = nested.get(obj, 'coordinates[0].value')
/* [11, 22] */
var x2 = nested.get(obj, 'coordinates[1].value[0]')
/* 33 */
var y2 = nested.get(obj, 'coordinates[1].value[1]')
/* 44 */

var x3 = nested.get(obj, 'coordinates[2].value[0]')
/* null */


Keywords

FAQs

Package last updated on 23 Feb 2017

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