aboutsummaryrefslogtreecommitdiff
path: root/node_modules/set-value/index.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-12-10 21:51:33 +0100
committerFlorian Dold <florian.dold@gmail.com>2017-12-10 21:51:33 +0100
commit0469abd4a9c9270a1fdc962969e36e63699af8b4 (patch)
treef9864d4a4148621378958794cbbfdc2393733283 /node_modules/set-value/index.js
parent6947e79bbc258f7bc96af424ddb71a511f0c15a3 (diff)
downloadwallet-core-0469abd4a9c9270a1fdc962969e36e63699af8b4.tar.xz
upgrade dependencies
Diffstat (limited to 'node_modules/set-value/index.js')
-rw-r--r--node_modules/set-value/index.js58
1 files changed, 23 insertions, 35 deletions
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;
+};