Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

include circular ref example in the readme, Traverse => traverse

  • Loading branch information...
commit 4a6285f71f4220550d4587090fd832ec9fcb10b7 1 parent ec1fb18
@substack authored
View
21 README.markdown
@@ -53,6 +53,27 @@ Output:
[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
+scrub circular references
+-------------------------
+
+scrub.js:
+
+````javascript
+var traverse = require('traverse');
+
+var obj = { a : 1, b : 2, c : [ 3, 4 ] };
+obj.c.push(obj);
+
+var scrubbed = traverse(obj).map(function (x) {
+ if (this.circular) this.remove()
+});
+console.dir(scrubbed);
+````
+
+output:
+
+ { a: 1, b: 2, c: [ 3, 4 ] }
+
context
=======
View
4 examples/json.js
@@ -1,10 +1,10 @@
-var Traverse = require('traverse');
+var traverse = require('traverse');
var id = 54;
var callbacks = {};
var obj = { moo : function () {}, foo : [2,3,4, function () {}] };
-var scrubbed = Traverse(obj).map(function (x) {
+var scrubbed = traverse(obj).map(function (x) {
if (typeof x === 'function') {
callbacks[id] = { id : id, f : x, path : this.path };
this.update('[Function]');
View
4 examples/leaves.js
@@ -1,4 +1,4 @@
-var Traverse = require('traverse');
+var traverse = require('traverse');
var obj = {
a : [1,2,3],
@@ -7,7 +7,7 @@ var obj = {
d : { e : [7,8], f : 9 },
};
-var leaves = Traverse(obj).reduce(function (acc, x) {
+var leaves = traverse(obj).reduce(function (acc, x) {
if (this.isLeaf) acc.push(x);
return acc;
}, []);
View
4 examples/negative.js
@@ -1,7 +1,7 @@
-var Traverse = require('traverse');
+var traverse = require('traverse');
var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
-Traverse(obj).forEach(function (x) {
+traverse(obj).forEach(function (x) {
if (x < 0) this.update(x + 128);
});
View
4 examples/stringify.js
@@ -1,10 +1,10 @@
#!/usr/bin/env node
-var Traverse = require('traverse');
+var traverse = require('traverse');
var obj = [ 'five', 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
var s = '';
-Traverse(obj).forEach(function to_s (node) {
+traverse(obj).forEach(function to_s (node) {
if (Array.isArray(node)) {
this.before(function () { s += '[' });
this.post(function (child) {

0 comments on commit 4a6285f

Please sign in to comment.
Something went wrong with that request. Please try again.