aboutsummaryrefslogtreecommitdiff
path: root/node_modules/set-value
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/set-value')
-rw-r--r--node_modules/set-value/README.md77
-rw-r--r--node_modules/set-value/index.js58
-rw-r--r--node_modules/set-value/package.json16
3 files changed, 104 insertions, 47 deletions
diff --git a/node_modules/set-value/README.md b/node_modules/set-value/README.md
index 19fbdbb4d..e336d744e 100644
--- a/node_modules/set-value/README.md
+++ b/node_modules/set-value/README.md
@@ -1,4 +1,4 @@
-# set-value [![NPM version](https://img.shields.io/npm/v/set-value.svg?style=flat)](https://www.npmjs.com/package/set-value) [![NPM monthly downloads](https://img.shields.io/npm/dm/set-value.svg?style=flat)](https://npmjs.org/package/set-value) [![NPM total downloads](https://img.shields.io/npm/dt/set-value.svg?style=flat)](https://npmjs.org/package/set-value) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/set-value.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/set-value)
+# set-value [![NPM version](https://img.shields.io/npm/v/set-value.svg?style=flat)](https://www.npmjs.com/package/set-value) [![NPM monthly downloads](https://img.shields.io/npm/dm/set-value.svg?style=flat)](https://npmjs.org/package/set-value) [![NPM total downloads](https://img.shields.io/npm/dt/set-value.svg?style=flat)](https://npmjs.org/package/set-value) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/set-value.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/set-value)
> Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.
@@ -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
@@ -42,7 +111,7 @@ Pull requests and stars are always welcome. For bugs and feature requests, [plea
| **Commits** | **Contributor** |
| --- | --- |
-| 53 | [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.4.2, on February 22, 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
diff --git a/node_modules/set-value/index.js b/node_modules/set-value/index.js
index e51ece557..000a77e2d 100644
--- a/node_modules/set-value/index.js
+++ b/node_modules/set-value/index.js
@@ -7,57 +7,45 @@
'use strict';
-var toPath = require('to-object-path');
+var split = require('split-string');
var extend = require('extend-shallow');
var isPlainObject = require('is-plain-object');
var isObject = require('is-extendable');
-module.exports = function(obj, path, val) {
+module.exports = function(obj, prop, val) {
if (!isObject(obj)) {
return obj;
}
- if (Array.isArray(path)) {
- path = toPath(path);
+ if (Array.isArray(prop)) {
+ prop = [].concat.apply([], prop).join('.');
}
- if (typeof path !== 'string') {
+ if (typeof prop !== 'string') {
return obj;
}
- var segs = path.split('.');
- var len = segs.length, i = -1;
- var res = obj;
- var last;
-
- while (++i < len) {
- var key = segs[i];
-
- while (key[key.length - 1] === '\\') {
- key = key.slice(0, -1) + '.' + segs[++i];
- }
-
- if (i === len - 1) {
- last = key;
- break;
- }
-
- if (!isObject(obj[key])) {
- obj[key] = {};
+ var keys = split(prop, {sep: '.', brackets: true});
+ var len = keys.length;
+ var idx = -1;
+ var current = obj;
+
+ while (++idx < len) {
+ var key = keys[idx];
+ if (idx !== len - 1) {
+ if (!isObject(current[key])) {
+ current[key] = {};
+ }
+ current = current[key];
+ continue;
}
- obj = obj[key];
- }
- if (obj.hasOwnProperty(last) && isObject(obj[last])) {
- if (isPlainObject(val)) {
- extend(obj[last], val);
+ if (isPlainObject(current[key]) && isPlainObject(val)) {
+ current[key] = extend({}, current[key], val);
} else {
- obj[last] = val;
+ current[key] = val;
}
-
- } else {
- obj[last] = val;
}
- return res;
-};
+ return obj;
+};
diff --git a/node_modules/set-value/package.json b/node_modules/set-value/package.json
index 83f065573..41cda4eb7 100644
--- a/node_modules/set-value/package.json
+++ b/node_modules/set-value/package.json
@@ -1,13 +1,13 @@
{
"name": "set-value",
"description": "Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.",
- "version": "0.4.3",
+ "version": "2.0.0",
"homepage": "https://github.com/jonschlinkert/set-value",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"contributors": [
- "<wtgtybhertgeghgtwtg@gmail.com> (https://github.com/wtgtybhertgeghgtwtg)",
- "Jon Schlinkert <jon.schlinkert@sellside.com> (http://twitter.com/jonschlinkert)",
- "Vadim Demedes <vdemedes@gmail.com> (https://vadimdemedes.com)"
+ "Jon Schlinkert (http://twitter.com/jonschlinkert)",
+ "(https://github.com/wtgtybhertgeghgtwtg)",
+ "Vadim Demedes (https://vadimdemedes.com)"
],
"repository": "jonschlinkert/set-value",
"bugs": {
@@ -27,12 +27,12 @@
"dependencies": {
"extend-shallow": "^2.0.1",
"is-extendable": "^0.1.1",
- "is-plain-object": "^2.0.1",
- "to-object-path": "^0.3.0"
+ "is-plain-object": "^2.0.3",
+ "split-string": "^3.0.1"
},
"devDependencies": {
- "gulp-format-md": "^0.1.10",
- "mocha": "^3.0.2"
+ "gulp-format-md": "^0.1.12",
+ "mocha": "^3.4.2"
},
"keywords": [
"get",