Comparing version 1.8.0 to 1.8.1
23
index.js
@@ -28,14 +28,7 @@ var keypather = module.exports = function (opts) { | ||
} | ||
var match = keypath.match(/(.*)([.]|\[["'])([^.\[]+)$/); | ||
if (match) { | ||
var lastKey = match[2]+match[3]; | ||
lastKey = ~lastKey.indexOf('.') ? | ||
lastKey.slice(1) : | ||
lastKey.slice(2, -2); | ||
var keypathWithoutLast = match[1]; | ||
this._get(obj, keypathWithoutLast)[lastKey] = value; | ||
} | ||
else { | ||
obj[keypath] = value; | ||
} | ||
this.keypathSplit = this.splitKeypath(keypath); | ||
var lastKey = this.getLastKey(); | ||
var val = this.getLastObj(arguments, true); | ||
val[lastKey] = value; | ||
return value; | ||
@@ -258,3 +251,3 @@ }; | ||
}; | ||
Keypather.prototype.getLastObj = function (args) { | ||
Keypather.prototype.getLastObj = function (args, setOperation) { | ||
var val; | ||
@@ -267,3 +260,5 @@ if (this.keypathSplit.length === 0) { | ||
getArgs[1] = this.keypathSplit.join('.'); | ||
val = this.get.apply(this, getArgs); | ||
val = setOperation ? | ||
this._get.apply(this, getArgs): | ||
this.get.apply(this, getArgs); | ||
} | ||
@@ -270,0 +265,0 @@ return val; |
{ | ||
"name": "keypather", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"description": "Get or set a object values from a keypath string. Supports bracket notation, dot notation, and functions", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,2 +21,6 @@ var keypather = require('../index')(); | ||
set("new.bar.foo.boom", 'value')); | ||
describe("valueForKeyPath.set(obj, '[\"new.bar.foo.boom\"]', 'value')", | ||
set('["new.bar.foo.boom"]', 'value')); | ||
describe("valueForKeyPath.set(obj, '[\"new.bar\"].what[\"foo.boom\"]', 'value')", | ||
set('[\"new.bar\"].what[\"foo.boom\"]', 'value')); | ||
}); | ||
@@ -23,0 +27,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38889
1009