1 # dot-prop [![Build Status](https://travis-ci.org/sindresorhus/dot-prop.svg?branch=master)](https://travis-ci.org/sindresorhus/dot-prop)
3 > Get, set, or delete a property from a nested object using a dot path
16 const dotProp = require('dot-prop');
19 dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar');
22 dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep');
25 dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value');
28 dotProp.get({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot');
32 const object = {foo: {bar: 'a'}};
33 dotProp.set(object, 'foo.bar', 'b');
35 //=> {foo: {bar: 'b'}}
37 const foo = dotProp.set({}, 'foo.bar', 'c');
39 //=> {foo: {bar: 'c'}}
41 dotProp.set(object, 'foo.baz', 'x');
43 //=> {foo: {bar: 'b', baz: 'x'}}
46 dotProp.has({foo: {bar: 'unicorn'}}, 'foo.bar');
50 const object = {foo: {bar: 'a'}};
51 dotProp.delete(object, 'foo.bar');
55 object.foo.bar = {x: 'y', y: 'x'};
56 dotProp.delete(object, 'foo.bar.x');
58 //=> {foo: {bar: {y: 'x'}}}
64 ### get(object, path, defaultValue?)
66 ### set(object, path, value)
72 ### delete(object, path)
74 Returns a boolean of whether the property existed before being deleted.
80 Object to get, set, or delete the `path` value.
82 You are allowed to pass in `undefined` as the object to the `get` and `has` functions.
88 Path of the property in the object, using `.` to separate each nested key.
90 Use `\\.` if you have a `.` in the key.
92 The following path components are invalid and results in `undefined` being returned: `__proto__`, `prototype`, `constructor`.
98 Value to set at `path`.
111 <a href="https://tidelift.com/subscription/pkg/npm-dot-prop?utm_source=npm-dot-prop&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
115 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.