Comparing version 1.2.1 to 1.2.3
10
index.js
@@ -5,3 +5,8 @@ function isObject (o) { | ||
function get (obj, path, dft) { | ||
function isBasic (b) { | ||
return 'string' === typeof b || 'number' === typeof b | ||
} | ||
function get (obj, path) { | ||
if(isBasic(path)) return obj[path] | ||
for(var i = 0; i < path.length; i++) { | ||
@@ -15,2 +20,3 @@ if(null == (obj = obj[path[i]])) return dft | ||
if(!obj) throw new Error('libnested.set: first arg must be an object') | ||
if(isBasic(path)) return obj[path] = value | ||
for(var i = 0; i < path.length; i++) | ||
@@ -59,1 +65,3 @@ if(i === path.length - 1) | ||
exports.paths = paths | ||
{ | ||
"name": "libnested", | ||
"description": "", | ||
"version": "1.2.1", | ||
"version": "1.2.3", | ||
"homepage": "https://github.com/dominictarr/libnested", | ||
@@ -15,3 +15,3 @@ "repository": { | ||
"scripts": { | ||
"test": "set -e; for t in test/*.js; do node $t; done" | ||
"test": "node test.js" | ||
}, | ||
@@ -18,0 +18,0 @@ "author": "'Dominic Tarr' <dominic.tarr@gmail.com> (dominictarr.com)", |
34
test.js
@@ -8,2 +8,20 @@ | ||
t.deepEqual( | ||
R.get({foo: true, bar: false}, 'foo'), | ||
true | ||
) | ||
t.deepEqual( | ||
R.get({foo: true, bar: false}, 'bar'), | ||
false | ||
) | ||
t.deepEqual( | ||
R.get({foo: true, bar: false}, ['foo']), | ||
true | ||
) | ||
t.deepEqual( | ||
R.get({foo: true, bar: false}, ['bar']), | ||
false | ||
) | ||
t.deepEqual( | ||
R.paths({foo: {bar: true}, baz: 2}), | ||
@@ -56,2 +74,17 @@ [ | ||
var a = R.set(deep, 'zak', 53) | ||
var a = R.set(deep, ['rom', 'pan', 2], 30) | ||
t.deepEqual( | ||
deep, | ||
{ | ||
foo: {bar: true}, | ||
baz: 2, | ||
blurg: {fop: {hif: []}}, | ||
rom: {pan: [1,2,30]}, | ||
zak: 53 | ||
} | ||
) | ||
t.end() | ||
@@ -62,2 +95,1 @@ | ||
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
5288
126
0
5