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

dot2val

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dot2val

Set or get a value within a deeply nested object using `dot' notation

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

dot2val

Build Status Code Climate npm:

Set or get a value within a deeply nested object using `dot' notation

Installation

npm install dot2val

Usage

var props = require('dot2val');

Given:

var obj = {
    prop1: {
        arr: ['a', 'b', 'c']
      , str: 'Hello'
    }
  , prop2: {
        arr: [ { nested: 'Universe' } ]
      , str: 'Hello again!'
    }
}

var arr = [ { foo: 'bar' } ];

Expect:

get
props.get(obj, 'prop1.str'); // => "Hello"
props.get(obj, 'prop1.arr.2'); // => "c"
props.get(obj, 'prop2.arr.0.nested'); // => "Universe"

props.get(arr, '0.foo'); // => "bar"

props.get(undefined, 'doesnt.matter'); // => undefined
props.get({}, 'doesnt.exist'); // => undefined
props.get({}, 'doesnt.exist', 'default value'); // => "default value"
set
props.set(obj, 'hello.universe', 'properties');
props.set(obj, 'hello', 'universe');

License

MIT

Keywords

FAQs

Package last updated on 19 Jul 2016

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