Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / configstore / node_modules / dot-prop / readme.md
1 # dot-prop [![Build Status](https://travis-ci.org/sindresorhus/dot-prop.svg?branch=master)](https://travis-ci.org/sindresorhus/dot-prop)
2
3 > Get, set, or delete a property from a nested object using a dot path
4
5
6 ## Install
7
8 ```
9 $ npm install --save dot-prop
10 ```
11
12
13 ## Usage
14
15 ```js
16 const dotProp = require('dot-prop');
17
18 // getter
19 dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar');
20 //=> 'unicorn'
21
22 dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep');
23 //=> undefined
24
25 dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value');
26 //=> 'default value'
27
28 dotProp.get({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot');
29 //=> 'unicorn'
30
31 // setter
32 const obj = {foo: {bar: 'a'}};
33 dotProp.set(obj, 'foo.bar', 'b');
34 console.log(obj);
35 //=> {foo: {bar: 'b'}}
36
37 const foo = dotProp.set({}, 'foo.bar', 'c');
38 console.log(foo);
39 //=> {foo: {bar: 'c'}}
40
41 dotProp.set(obj, 'foo.baz', 'x');
42 console.log(obj);
43 //=> {foo: {bar: 'b', baz: 'x'}}
44
45 // has
46 dotProp.has({foo: {bar: 'unicorn'}}, 'foo.bar');
47 //=> true
48
49 // deleter
50 const obj = {foo: {bar: 'a'}};
51 dotProp.delete(obj, 'foo.bar');
52 console.log(obj);
53 //=> {foo: {}}
54
55 obj.foo.bar = {x: 'y', y: 'x'};
56 dotProp.delete(obj, 'foo.bar.x');
57 console.log(obj);
58 //=> {foo: {bar: {y: 'x'}}}
59 ```
60
61
62 ## API
63
64 ### get(obj, path, [defaultValue])
65
66 ### set(obj, path, value)
67
68 Returns the object.
69
70 ### has(obj, path)
71
72 ### delete(obj, path)
73
74 #### obj
75
76 Type: `Object`
77
78 Object to get, set, or delete the `path` value.
79
80 #### path
81
82 Type: `string`
83
84 Path of the property in the object, using `.` to separate each nested key.
85
86 Use `\\.` if you have a `.` in the key.
87
88 The following path components are invalid and results in `undefined` being returned: `__proto__`, `prototype`, `constructor`.
89
90 #### value
91
92 Type: `any`
93
94 Value to set at `path`.
95
96 #### defaultValue
97
98 Type: `any`
99
100 Default value.
101
102
103 ## License
104
105 MIT © [Sindre Sorhus](https://sindresorhus.com)