Comparing version 0.5.1 to 0.6.0
16
index.js
@@ -15,3 +15,3 @@ var traverse = require("traverse"), | ||
}, | ||
update: function(cb) { | ||
@@ -21,4 +21,5 @@ this.forEach(function(node) { | ||
}); | ||
return obj; | ||
}, | ||
remove: function() { | ||
@@ -28,8 +29,9 @@ this.forEach(function(node) { | ||
}) | ||
return obj; | ||
}, | ||
condense: function() { | ||
traverse(obj).forEach(function(node) { | ||
if (!this.parent) return; | ||
if (this.parent.keep) { | ||
@@ -58,4 +60,5 @@ this.keep = true; | ||
}); | ||
return obj; | ||
}, | ||
forEach: function(cb) { | ||
@@ -68,5 +71,6 @@ traverse(obj).forEach(function(node) { | ||
// inherit context from js-traverse | ||
cb.call(this, node); | ||
cb.call(this, node); | ||
} | ||
}); | ||
return obj; | ||
} | ||
@@ -73,0 +77,0 @@ }; |
{ | ||
"name": "js-select", | ||
"description": "Traverse and modify objects with JSONSelect selectors", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"author": "Heather Arthur <fayearthur@gmail.com>", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -35,3 +35,3 @@ var assert = require("assert"), | ||
var people2; | ||
var people2, obj; | ||
@@ -63,3 +63,3 @@ assert.deepEqual(select(people, "*").nodes(), [{"george":{"age":35,"movies":[{"name":"Repo Man","stars":5}]},"mary":{"age":15,"movies":[{"name":"Twilight","stars":3},{"name":"Trudy","stars":2},{"name":"The Fighter","stars":4}]},"chris":{"car":null,"male":true}},{"age":35,"movies":[{"name":"Repo Man","stars":5}]},35,[{"name":"Repo Man","stars":5}],{"name":"Repo Man","stars":5},"Repo Man",5,{"age":15,"movies":[{"name":"Twilight","stars":3},{"name":"Trudy","stars":2},{"name":"The Fighter","stars":4}]},15,[{"name":"Twilight","stars":3},{"name":"Trudy","stars":2},{"name":"The Fighter","stars":4}],{"name":"Twilight","stars":3},"Twilight",3,{"name":"Trudy","stars":2},"Trudy",2,{"name":"The Fighter","stars":4},"The Fighter",4,{"car":null,"male":true},null,true]); | ||
assert.deepEqual(select(people, ":only-child").nodes(), [{"name":"Repo Man","stars":5}]); | ||
assert.deepEqual(select(people, ":root").nodes(),[{"george":{"age":35,"movies":[{"name":"Repo Man","stars":5}]},"mary":{"age":15,"movies":[{"name":"Twilight","stars":3},{"name":"Trudy","stars":2},{"name":"The Fighter","stars":4}]},"chris":{"car":null,"male":true}}]) | ||
assert.deepEqual(select(people, ":root").nodes(),[{"george":{"age":35,"movies":[{"name":"Repo Man","stars":5}]},"mary":{"age":15,"movies":[{"name":"Twilight","stars":3},{"name":"Trudy","stars":2},{"name":"The Fighter","stars":4}]},"chris":{"car":null,"male":true}}]) | ||
@@ -97,4 +97,5 @@ assert.deepEqual(select(people, "string").nodes(),["Repo Man","Twilight","Trudy","The Fighter"]); | ||
select(people2, ".age").update(3) | ||
obj = select(people2, ".age").update(3) | ||
assert.deepEqual(select(people2, ".age").nodes(), [3, 3]); | ||
assert.deepEqual(obj, people2); | ||
@@ -104,4 +105,5 @@ // remove() | ||
select(people2, ".age").remove(); | ||
obj = select(people2, ".age").remove(); | ||
assert.deepEqual(select(people2, ".age").nodes(), []); | ||
assert.deepEqual(obj, people2); | ||
@@ -118,4 +120,5 @@ // condense() | ||
people2 = traverse.clone(people); | ||
select(people2, ".stars").condense(); | ||
obj = select(people2, ".stars").condense(); | ||
assert.deepEqual(people2, {"george": {movies: [{stars: 5}]}, "mary": {movies: [{stars: 3},{stars: 2},{stars: 4}]}}); | ||
assert.deepEqual(obj, people2); | ||
@@ -125,6 +128,7 @@ // forEach() | ||
select(people2, ".age").forEach(function(age) { | ||
obj = select(people2, ".age").forEach(function(age) { | ||
this.update(age - 5); | ||
}) | ||
assert.deepEqual(select(people2, ".age").nodes(), [30, 10]); | ||
assert.deepEqual(obj, people2); | ||
@@ -131,0 +135,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
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
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
0
2
158178
9
1781