Comparing version 0.5.2 to 0.6.0
@@ -0,1 +1,5 @@ | ||
0.6.0 / 2019-05-01 | ||
================== | ||
* feat: support setting dotted paths within nested arrays | ||
0.5.2 / 2019-04-25 | ||
@@ -2,0 +6,0 @@ ================== |
@@ -257,13 +257,3 @@ // These properties are special and can open client libraries to security | ||
if (!copy && Array.isArray(val)) { | ||
for (var item, j = 0; j < obj.length && j < val.length; ++j) { | ||
item = obj[j]; | ||
if (item) { | ||
if (lookup) { | ||
lookup(item, part, map(val[j])); | ||
} else { | ||
if (item[special]) item = item[special]; | ||
item[part] = map(val[j]); | ||
} | ||
} | ||
} | ||
_setArray(obj, val, part, lookup, special, map); | ||
} else { | ||
@@ -294,2 +284,22 @@ for (var j = 0; j < obj.length; ++j) { | ||
/*! | ||
* Recursively set nested arrays | ||
*/ | ||
function _setArray(obj, val, part, lookup, special, map) { | ||
for (var item, j = 0; j < obj.length && j < val.length; ++j) { | ||
item = obj[j]; | ||
if (Array.isArray(item) && Array.isArray(val[j])) { | ||
_setArray(item, val[j], part, lookup, special, map); | ||
} else if (item) { | ||
if (lookup) { | ||
lookup(item, part, map(val[j])); | ||
} else { | ||
if (item[special]) item = item[special]; | ||
item[part] = map(val[j]); | ||
} | ||
} | ||
} | ||
} | ||
/*! | ||
* Returns the value passed to it. | ||
@@ -296,0 +306,0 @@ */ |
{ | ||
"name": "mpath", | ||
"version": "0.5.2", | ||
"version": "0.6.0", | ||
"description": "{G,S}et object values using MongoDB-like path notation", | ||
@@ -22,5 +22,5 @@ "main": "index.js", | ||
"devDependencies": { | ||
"mocha": "1.8.1", | ||
"mocha": "5.x", | ||
"benchmark": "~1.0.0" | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
'use strict'; | ||
@@ -1752,3 +1753,3 @@ /** | ||
done(); | ||
}) | ||
}); | ||
@@ -1777,5 +1778,11 @@ it('array.prop', function(done){ | ||
done(); | ||
}) | ||
}); | ||
}) | ||
it('nested array', function(done) { | ||
const obj = { arr: [[{ test: 41 }]] }; | ||
mpath.set('arr.test', [[42]], obj); | ||
assert.deepEqual(obj.arr, [[{ test: 42 }]]); | ||
done(); | ||
}); | ||
}); | ||
@@ -1789,4 +1796,4 @@ describe('multiple $ use', function(){ | ||
done(); | ||
}) | ||
}) | ||
}); | ||
}); | ||
@@ -1793,0 +1800,0 @@ it('has', function(done) { |
Sorry, the diff of this file is not supported yet
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
88480
1990