Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

traverse

Package Overview
Dependencies
Maintainers
0
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

traverse - npm Package Compare versions

Comparing version 0.3.6 to 0.3.7

.npmignore

21

index.js

@@ -59,5 +59,14 @@ module.exports = Traverse;

//this.stop();
return undefined;
}).bind(this);
if (this.key) node = node[this.key];
if (!this.isRoot) {
/*
if (!Object.hasOwnProperty.call(node, this.key)) {
return notEqual();
}
*/
node = node[this.key];
}
var x = node;

@@ -111,3 +120,3 @@

var ky = Object.keys(y);
if (kx.length !== ky.length) return false;
if (kx.length !== ky.length) return notEqual();
for (var i = 0; i < kx.length; i++) {

@@ -212,4 +221,4 @@ var k = kx[i];

if (typeof node == 'object' && node !== null) {
state.isLeaf = Object.keys(node).length == 0
if (typeof node === 'object' && node !== null) {
state.isLeaf = Object.keys(node).length == 0;

@@ -246,3 +255,5 @@ for (var i = 0; i < parents.length; i++) {

var child = walker(state.node[key]);
if (immutable) state.node[key] = child.node;
if (immutable && Object.hasOwnProperty.call(state.node, key)) {
state.node[key] = child.node;
}

@@ -249,0 +260,0 @@ child.isLast = i == keys.length - 1;

{
"name" : "traverse",
"version" : "0.3.6",
"version" : "0.3.7",
"description" : "Traverse and transform objects by visiting every node on a recursive walk",

@@ -13,4 +13,3 @@ "author" : "James Halliday",

"devDependencies" : {
"seq" : ">=0.1.7",
"expresso" : ">=0.6.0"
"expresso" : "0.7.x"
},

@@ -17,0 +16,0 @@ "scripts" : {

@@ -99,1 +99,17 @@ var assert = require('assert');

};
exports.circMapScrub = function () {
var obj = { a : 1, b : 2 };
obj.c = obj;
var scrubbed = Traverse(obj).map(function (node) {
if (this.circular) this.remove();
});
assert.deepEqual(
Object.keys(scrubbed).sort(),
[ 'a', 'b' ]
);
assert.ok(Traverse.deepEqual(scrubbed, { a : 1, b : 2 }));
assert.equal(obj.c, obj);
};

@@ -95,2 +95,88 @@ var assert = require('assert');

exports.falsy = function () {
assert.ok(!traverse.deepEqual(
[ undefined ],
[ null ],
'null is not undefined!'
));
assert.ok(!traverse.deepEqual(
[ null ],
[ undefined ],
'undefined is not null!'
));
assert.ok(!traverse.deepEqual(
{ a : 1, b : 2, c : [ 3, undefined, 5 ] },
{ a : 1, b : 2, c : [ 3, null, 5 ] },
'undefined is not null, however deeply!'
));
assert.ok(!traverse.deepEqual(
{ a : 1, b : 2, c : [ 3, undefined, 5 ] },
{ a : 1, b : 2, c : [ 3, null, 5 ] },
'null is not undefined, however deeply!'
));
assert.ok(!traverse.deepEqual(
{ a : 1, b : 2, c : [ 3, undefined, 5 ] },
{ a : 1, b : 2, c : [ 3, null, 5 ] },
'null is not undefined, however deeply!'
));
};
exports.deletedArrayEqual = function () {
var xs = [ 1, 2, 3, 4 ];
delete xs[2];
var ys = Object.create(Array.prototype);
ys[0] = 1;
ys[1] = 2;
ys[3] = 4;
assert.ok(traverse.deepEqual(
xs, ys,
'arrays with deleted elements are only equal to'
+ ' arrays with similarly deleted elements'
));
assert.ok(!traverse.deepEqual(
xs,
[ 1, 2, undefined, 4 ],
'deleted array elements cannot be undefined'
));
assert.ok(!traverse.deepEqual(
xs,
[ 1, 2, null, 4 ],
'deleted array elements cannot be null'
));
};
exports.deletedObjectEqual = function () {
var obj = { a : 1, b : 2, c : 3 };
delete obj.c;
assert.ok(traverse.deepEqual(
obj, { a : 1, b : 2 },
'deleted object elements should not show up'
));
assert.ok(!traverse.deepEqual(
obj, { a : 1, b : 2, c : undefined },
'deleted object elements are not undefined'
));
assert.ok(!traverse.deepEqual(
obj, { a : 1, b : 2, c : null },
'deleted object elements are not null'
));
};
exports.emptyKeyEqual = function () {
assert.ok(!traverse.deepEqual(
{ a : 1 }, { a : 1, '' : 55 }
));
};
exports.deepArguments = function () {

@@ -97,0 +183,0 @@ assert.ok(!traverse.deepEqual(

@@ -89,1 +89,116 @@ var assert = require('assert');

};
exports.remove = function () {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
Traverse(obj).forEach(function (x) {
if (this.isLeaf && x % 2 == 0) this.remove();
});
assert.deepEqual(obj, { a : 1, c : [ 3 ] });
};
exports.removeMap = function () {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
var res = Traverse(obj).map(function (x) {
if (this.isLeaf && x % 2 == 0) this.remove();
});
assert.deepEqual(obj, { a : 1, b : 2, c : [ 3, 4 ] });
assert.deepEqual(res, { a : 1, c : [ 3 ] });
};
exports.delete = function () {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
Traverse(obj).forEach(function (x) {
if (this.isLeaf && x % 2 == 0) this.delete();
});
assert.ok(!Traverse.deepEqual(
obj, { a : 1, c : [ 3, undefined ] }
));
assert.ok(Traverse.deepEqual(
obj, { a : 1, c : [ 3 ] }
));
assert.ok(!Traverse.deepEqual(
obj, { a : 1, c : [ 3, null ] }
));
};
exports.deleteRedux = function () {
var obj = { a : 1, b : 2, c : [ 3, 4, 5 ] };
Traverse(obj).forEach(function (x) {
if (this.isLeaf && x % 2 == 0) this.delete();
});
assert.ok(!Traverse.deepEqual(
obj, { a : 1, c : [ 3, undefined, 5 ] }
));
assert.ok(Traverse.deepEqual(
obj, { a : 1, c : [ 3 ,, 5 ] }
));
assert.ok(!Traverse.deepEqual(
obj, { a : 1, c : [ 3, null, 5 ] }
));
assert.ok(!Traverse.deepEqual(
obj, { a : 1, c : [ 3, 5 ] }
));
};
exports.deleteMap = function () {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
var res = Traverse(obj).map(function (x) {
if (this.isLeaf && x % 2 == 0) this.delete();
});
assert.ok(Traverse.deepEqual(
obj,
{ a : 1, b : 2, c : [ 3, 4 ] }
));
var xs = [ 3, 4 ];
delete xs[1];
assert.ok(Traverse.deepEqual(
res, { a : 1, c : xs }
));
assert.ok(Traverse.deepEqual(
res, { a : 1, c : [ 3, ] }
));
assert.ok(Traverse.deepEqual(
res, { a : 1, c : [ 3 ] }
));
};
exports.deleteMapRedux = function () {
var obj = { a : 1, b : 2, c : [ 3, 4, 5 ] };
var res = Traverse(obj).map(function (x) {
if (this.isLeaf && x % 2 == 0) this.delete();
});
assert.ok(Traverse.deepEqual(
obj,
{ a : 1, b : 2, c : [ 3, 4, 5 ] }
));
var xs = [ 3, 4, 5 ];
delete xs[1];
assert.ok(Traverse.deepEqual(
res, { a : 1, c : xs }
));
assert.ok(!Traverse.deepEqual(
res, { a : 1, c : [ 3, 5 ] }
));
assert.ok(Traverse.deepEqual(
res, { a : 1, c : [ 3 ,, 5 ] }
));
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc