From 197399e6e4eddf203a3e0f85351d4d8c89e60725 Mon Sep 17 00:00:00 2001 From: jonschlinkert Date: Wed, 21 Jun 2017 01:47:35 -0400 Subject: [PATCH] update docs, run verb to generate readme --- .verb.md | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++- README.md | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 143 insertions(+), 4 deletions(-) diff --git a/.verb.md b/.verb.md index f713462..36ae3d0 100644 --- a/.verb.md +++ b/.verb.md @@ -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({}, ".c", "d")); +//=> { '': { 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! diff --git a/README.md b/README.md index 24bbd9e..e336d74 100644 --- a/README.md +++ b/README.md @@ -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({}, ".c", "d")); +//=> { '': { 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 @@ -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) | @@ -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._ \ No newline at end of file +_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 21, 2017._ \ No newline at end of file