Skip to content

Commit

Permalink
update docs, run verb to generate readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Jun 21, 2017
1 parent 30466a3 commit 197399e
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 4 deletions.
72 changes: 71 additions & 1 deletion .verb.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,79 @@

```js
var set = require('{%= name %}');
set(object, prop, value);
```

### Params

- `object` **{object}**: The object to set `value` on
- `prop` **{string}**: The property to set. Dot-notation may be used.
- `value` **{any}**: The value to set on `object[prop]`


## Examples

Updates and returns the given object:

```js
var obj = {};
set(obj, 'a.b.c', 'd');
console.log(obj);
//=> {a: {b: c: 'd'}}
//=> { a: { b: { c: 'd' } } }
```

### Escaping

**Escaping with backslashes**

Prevent set-value from splitting on a dot by prefixing it with backslashes:

```js
console.log(set({}, 'a\\.b.c', 'd'));
//=> { 'a.b': { c: 'd' } }

console.log(set({}, 'a\\.b\\.c', 'd'));
//=> { 'a.b.c': 'd' }
```

**Escaping with double-quotes or single-quotes**

Wrap double or single quotes around the string, or part of the string, that should not be split by set-value:

```js
console.log(set({}, '"a.b".c', 'd'));
//=> { 'a.b': { c: 'd' } }

console.log(set({}, "'a.b'.c", "d"));
//=> { 'a.b': { c: 'd' } }

console.log(set({}, '"this/is/a/.file.path"', 'd'));
//=> { 'this/is/a/file.path': 'd' }
```

### Bracket support

set-value does not split inside brackets or braces:

```js
console.log(set({}, '[a.b].c', 'd'));
//=> { '[a.b]': { c: 'd' } }

console.log(set({}, "(a.b).c", "d"));
//=> { '(a.b)': { c: 'd' } }

console.log(set({}, "<a.b>.c", "d"));
//=> { '<a.b>': { c: 'd' } }

console.log(set({}, "{a..b}.c", "d"));
//=> { '{a..b}': { c: 'd' } }
```

## History

### v2.0.0

- Adds support for escaping with double or single quotes. See [escaping](#escaping) for examples.
- Will no longer split inside brackets or braces. See [bracket support](#bracket-support) for examples.

If there are any regressions please create a [bug report](../../issues/new). Thanks!
75 changes: 72 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,82 @@ $ npm install --save set-value

```js
var set = require('set-value');
set(object, prop, value);
```

### Params

* `object` **{object}**: The object to set `value` on
* `prop` **{string}**: The property to set. Dot-notation may be used.
* `value` **{any}**: The value to set on `object[prop]`

## Examples

Updates and returns the given object:

```js
var obj = {};
set(obj, 'a.b.c', 'd');
console.log(obj);
//=> {a: {b: c: 'd'}}
//=> { a: { b: { c: 'd' } } }
```

### Escaping

**Escaping with backslashes**

Prevent set-value from splitting on a dot by prefixing it with backslashes:

```js
console.log(set({}, 'a\\.b.c', 'd'));
//=> { 'a.b': { c: 'd' } }

console.log(set({}, 'a\\.b\\.c', 'd'));
//=> { 'a.b.c': 'd' }
```

**Escaping with double-quotes or single-quotes**

Wrap double or single quotes around the string, or part of the string, that should not be split by set-value:

```js
console.log(set({}, '"a.b".c', 'd'));
//=> { 'a.b': { c: 'd' } }

console.log(set({}, "'a.b'.c", "d"));
//=> { 'a.b': { c: 'd' } }

console.log(set({}, '"this/is/a/.file.path"', 'd'));
//=> { 'this/is/a/file.path': 'd' }
```

### Bracket support

set-value does not split inside brackets or braces:

```js
console.log(set({}, '[a.b].c', 'd'));
//=> { '[a.b]': { c: 'd' } }

console.log(set({}, "(a.b).c", "d"));
//=> { '(a.b)': { c: 'd' } }

console.log(set({}, "<a.b>.c", "d"));
//=> { '<a.b>': { c: 'd' } }

console.log(set({}, "{a..b}.c", "d"));
//=> { '{a..b}': { c: 'd' } }
```

## History

### v2.0.0

* Adds support for escaping with double or single quotes. See [escaping](#escaping) for examples.
* Will no longer split inside brackets or braces. See [bracket support](#bracket-support) for examples.

If there are any regressions please create a [bug report](../../issues/new). Thanks!

## About

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

| **Commits** | **Contributor** |
| --- | --- |
| 56 | [jonschlinkert](https://github.com/jonschlinkert) |
| 59 | [jonschlinkert](https://github.com/jonschlinkert) |
| 1 | [vadimdemedes](https://github.com/vadimdemedes) |
| 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |

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

***

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

0 comments on commit 197399e

Please sign in to comment.