Comparing version 0.2.4 to 0.2.5
@@ -116,3 +116,3 @@ module.exports = Traverse; | ||
key : path.slice(-1)[0], | ||
isRoot : node === root, | ||
isRoot : path.length === 0, | ||
level : path.length, | ||
@@ -119,0 +119,0 @@ circular : null, |
{ | ||
"name" : "traverse", | ||
"version" : "0.2.4", | ||
"version" : "0.2.5", | ||
"description" : "Traverse and transform objects by visiting every node on a recursive walk.", | ||
@@ -5,0 +5,0 @@ "author" : "James Halliday", |
@@ -1,3 +0,1 @@ | ||
#!/usr/bin/env node | ||
var sys = require('sys'); | ||
var Traverse = require('traverse'); | ||
@@ -11,3 +9,3 @@ | ||
var scrubbed = Traverse(obj).map(function (x) { | ||
if (x instanceof Function) { | ||
if (typeof x === 'function') { | ||
callbacks[id] = { id : id, f : x, path : this.path }; | ||
@@ -17,3 +15,3 @@ this.update('[Function]'); | ||
} | ||
}).value; | ||
}).get(); | ||
@@ -24,26 +22,28 @@ assert.equal( | ||
); | ||
assert.equal( | ||
scrubbed.foo[3], '[Function]', | ||
'obj.foo[3] replaced with "[Function]"' | ||
) | ||
assert.equal( | ||
JSON.stringify(scrubbed), | ||
'{"moo":"[Function]","foo":[2,3,4,"[Function]"]}', | ||
'Full JSON string matches' | ||
); | ||
assert.equal( | ||
assert.eql(scrubbed, { | ||
moo : '[Function]', | ||
foo : [ 2, 3, 4, "[Function]" ] | ||
}, 'Full JSON string matches'); | ||
assert.eql( | ||
typeof obj.moo, 'function', | ||
'Original obj.moo still a function' | ||
); | ||
assert.equal( | ||
assert.eql( | ||
typeof obj.foo[3], 'function', | ||
'Original obj.foo[3] still a function' | ||
); | ||
assert.equal( | ||
sys.inspect(callbacks), | ||
"{ '54': { id: 54, f: [Function], path: [ 'moo' ] }\n" | ||
+ ", '55': { id: 55, f: [Function], path: [ 'foo', '3' ] }\n}", | ||
'Check the generated callbacks list' | ||
); | ||
assert.eql(callbacks, { | ||
54: { id: 54, f : obj.moo, path: [ 'moo' ] }, | ||
55: { id: 55, f : obj.foo[3], path: [ 'foo', '3' ] }, | ||
}, 'Check the generated callbacks list'); | ||
}; | ||
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
30614
20
790