Big news!Introducing Socket AI - ChatGPT-Powered Threat Analysis. Learn more
Socket
Log inDemoInstall

dot-prop-legacy

Package Overview
Dependencies
1
Maintainers
1
Versions
1
Issues
File Explorer

Advanced tools

dot-prop-legacy

Get, set, or delete a property from a nested object using a dot path

    4.2.1latest
    GitHub

Version published
Maintainers
1
Weekly downloads
236
decreased by-51.04%

Weekly downloads

Readme

Source

dot-prop-legacy Build Status

:warning: This is a fork of the original dot-prop project with the only goal of keeping a legacy release line to make life of developers still supporting node@6 a little bit easier.

Get, set, or delete a property from a nested object using a dot path

Install

$ npm install --save dot-prop@npm:dot-prop-legacy

Usage

const dotProp = require('dot-prop'); // getter dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar'); //=> 'unicorn' dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep'); //=> undefined dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value'); //=> 'default value' dotProp.get({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot'); //=> 'unicorn' // setter const obj = {foo: {bar: 'a'}}; dotProp.set(obj, 'foo.bar', 'b'); console.log(obj); //=> {foo: {bar: 'b'}} const foo = dotProp.set({}, 'foo.bar', 'c'); console.log(foo); //=> {foo: {bar: 'c'}} dotProp.set(obj, 'foo.baz', 'x'); console.log(obj); //=> {foo: {bar: 'b', baz: 'x'}} // has dotProp.has({foo: {bar: 'unicorn'}}, 'foo.bar'); //=> true // deleter const obj = {foo: {bar: 'a'}}; dotProp.delete(obj, 'foo.bar'); console.log(obj); //=> {foo: {}} obj.foo.bar = {x: 'y', y: 'x'}; dotProp.delete(obj, 'foo.bar.x'); console.log(obj); //=> {foo: {bar: {y: 'x'}}}

API

get(obj, path, [defaultValue])

set(obj, path, value)

Returns the object.

has(obj, path)

delete(obj, path)

obj

Type: Object

Object to get, set, or delete the path value.

path

Type: string

Path of the property in the object, using . to separate each nested key.

Use \\. if you have a . in the key.

The following path components are invalid and results in undefined being returned: __proto__, prototype, constructor.

value

Type: any

Value to set at path.

defaultValue

Type: any

Default value.

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 14 Aug 2020

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc