Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / 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 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 object = {foo: {bar: 'a'}};
33 dotProp.set(object, 'foo.bar', 'b');
34 console.log(object);
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(object, 'foo.baz', 'x');
42 console.log(object);
43 //=> {foo: {bar: 'b', baz: 'x'}}
44
45 // Has
46 dotProp.has({foo: {bar: 'unicorn'}}, 'foo.bar');
47 //=> true
48
49 // Deleter
50 const object = {foo: {bar: 'a'}};
51 dotProp.delete(object, 'foo.bar');
52 console.log(object);
53 //=> {foo: {}}
54
55 object.foo.bar = {x: 'y', y: 'x'};
56 dotProp.delete(object, 'foo.bar.x');
57 console.log(object);
58 //=> {foo: {bar: {y: 'x'}}}
59 ```
60
61
62 ## API
63
64 ### get(object, path, defaultValue?)
65
66 ### set(object, path, value)
67
68 Returns the object.
69
70 ### has(object, path)
71
72 ### delete(object, path)
73
74 Returns a boolean of whether the property existed before being deleted.
75
76 #### object
77
78 Type: `object`
79
80 Object to get, set, or delete the `path` value.
81
82 You are allowed to pass in `undefined` as the object to the `get` and `has` functions.
83
84 #### path
85
86 Type: `string`
87
88 Path of the property in the object, using `.` to separate each nested key.
89
90 Use `\\.` if you have a `.` in the key.
91
92 The following path components are invalid and results in `undefined` being returned: `__proto__`, `prototype`, `constructor`.
93
94 #### value
95
96 Type: `unknown`
97
98 Value to set at `path`.
99
100 #### defaultValue
101
102 Type: `unknown`
103
104 Default value.
105
106
107 ---
108
109 <div align="center">
110         <b>
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>
112         </b>
113         <br>
114         <sub>
115                 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
116         </sub>
117 </div>