Skip to content

Commit 197399e

Browse files
committed
update docs, run verb to generate readme
1 parent 30466a3 commit 197399e

File tree

2 files changed

+143
-4
lines changed

2 files changed

+143
-4
lines changed

.verb.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,79 @@
22

33
```js
44
var set = require('{%= name %}');
5+
set(object, prop, value);
6+
```
7+
8+
### Params
9+
10+
- `object` **{object}**: The object to set `value` on
11+
- `prop` **{string}**: The property to set. Dot-notation may be used.
12+
- `value` **{any}**: The value to set on `object[prop]`
13+
14+
15+
## Examples
516

17+
Updates and returns the given object:
18+
19+
```js
620
var obj = {};
721
set(obj, 'a.b.c', 'd');
822
console.log(obj);
9-
//=> {a: {b: c: 'd'}}
23+
//=> { a: { b: { c: 'd' } } }
1024
```
25+
26+
### Escaping
27+
28+
**Escaping with backslashes**
29+
30+
Prevent set-value from splitting on a dot by prefixing it with backslashes:
31+
32+
```js
33+
console.log(set({}, 'a\\.b.c', 'd'));
34+
//=> { 'a.b': { c: 'd' } }
35+
36+
console.log(set({}, 'a\\.b\\.c', 'd'));
37+
//=> { 'a.b.c': 'd' }
38+
```
39+
40+
**Escaping with double-quotes or single-quotes**
41+
42+
Wrap double or single quotes around the string, or part of the string, that should not be split by set-value:
43+
44+
```js
45+
console.log(set({}, '"a.b".c', 'd'));
46+
//=> { 'a.b': { c: 'd' } }
47+
48+
console.log(set({}, "'a.b'.c", "d"));
49+
//=> { 'a.b': { c: 'd' } }
50+
51+
console.log(set({}, '"this/is/a/.file.path"', 'd'));
52+
//=> { 'this/is/a/file.path': 'd' }
53+
```
54+
55+
### Bracket support
56+
57+
set-value does not split inside brackets or braces:
58+
59+
```js
60+
console.log(set({}, '[a.b].c', 'd'));
61+
//=> { '[a.b]': { c: 'd' } }
62+
63+
console.log(set({}, "(a.b).c", "d"));
64+
//=> { '(a.b)': { c: 'd' } }
65+
66+
console.log(set({}, "<a.b>.c", "d"));
67+
//=> { '<a.b>': { c: 'd' } }
68+
69+
console.log(set({}, "{a..b}.c", "d"));
70+
//=> { '{a..b}': { c: 'd' } }
71+
```
72+
73+
## History
74+
75+
### v2.0.0
76+
77+
- Adds support for escaping with double or single quotes. See [escaping](#escaping) for examples.
78+
- Will no longer split inside brackets or braces. See [bracket support](#bracket-support) for examples.
79+
80+
If there are any regressions please create a [bug report](../../issues/new). Thanks!

README.md

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,82 @@ $ npm install --save set-value
1414

1515
```js
1616
var set = require('set-value');
17+
set(object, prop, value);
18+
```
19+
20+
### Params
21+
22+
* `object` **{object}**: The object to set `value` on
23+
* `prop` **{string}**: The property to set. Dot-notation may be used.
24+
* `value` **{any}**: The value to set on `object[prop]`
25+
26+
## Examples
1727

28+
Updates and returns the given object:
29+
30+
```js
1831
var obj = {};
1932
set(obj, 'a.b.c', 'd');
2033
console.log(obj);
21-
//=> {a: {b: c: 'd'}}
34+
//=> { a: { b: { c: 'd' } } }
35+
```
36+
37+
### Escaping
38+
39+
**Escaping with backslashes**
40+
41+
Prevent set-value from splitting on a dot by prefixing it with backslashes:
42+
43+
```js
44+
console.log(set({}, 'a\\.b.c', 'd'));
45+
//=> { 'a.b': { c: 'd' } }
46+
47+
console.log(set({}, 'a\\.b\\.c', 'd'));
48+
//=> { 'a.b.c': 'd' }
49+
```
50+
51+
**Escaping with double-quotes or single-quotes**
52+
53+
Wrap double or single quotes around the string, or part of the string, that should not be split by set-value:
54+
55+
```js
56+
console.log(set({}, '"a.b".c', 'd'));
57+
//=> { 'a.b': { c: 'd' } }
58+
59+
console.log(set({}, "'a.b'.c", "d"));
60+
//=> { 'a.b': { c: 'd' } }
61+
62+
console.log(set({}, '"this/is/a/.file.path"', 'd'));
63+
//=> { 'this/is/a/file.path': 'd' }
64+
```
65+
66+
### Bracket support
67+
68+
set-value does not split inside brackets or braces:
69+
70+
```js
71+
console.log(set({}, '[a.b].c', 'd'));
72+
//=> { '[a.b]': { c: 'd' } }
73+
74+
console.log(set({}, "(a.b).c", "d"));
75+
//=> { '(a.b)': { c: 'd' } }
76+
77+
console.log(set({}, "<a.b>.c", "d"));
78+
//=> { '<a.b>': { c: 'd' } }
79+
80+
console.log(set({}, "{a..b}.c", "d"));
81+
//=> { '{a..b}': { c: 'd' } }
2282
```
2383

84+
## History
85+
86+
### v2.0.0
87+
88+
* Adds support for escaping with double or single quotes. See [escaping](#escaping) for examples.
89+
* Will no longer split inside brackets or braces. See [bracket support](#bracket-support) for examples.
90+
91+
If there are any regressions please create a [bug report](../../issues/new). Thanks!
92+
2493
## About
2594

2695
### Related projects
@@ -42,7 +111,7 @@ Pull requests and stars are always welcome. For bugs and feature requests, [plea
42111

43112
| **Commits** | **Contributor** |
44113
| --- | --- |
45-
| 56 | [jonschlinkert](https://github.com/jonschlinkert) |
114+
| 59 | [jonschlinkert](https://github.com/jonschlinkert) |
46115
| 1 | [vadimdemedes](https://github.com/vadimdemedes) |
47116
| 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
48117

@@ -78,4 +147,4 @@ Released under the [MIT License](LICENSE).
78147

79148
***
80149

81-
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 19, 2017._
150+
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 21, 2017._

0 commit comments

Comments
 (0)