Skip to content

Commit

Permalink
updated readme and negative example with new style
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Sep 4, 2010
1 parent a8d1645 commit 5aa3f84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
21 changes: 10 additions & 11 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ These examples use node.js, but the module should work without it.
Collect Leaf Nodes
------------------
var sys = require('sys');
var Traverse = require('traverse').Traverse;
var Traverse = require('traverse');

var acc = [];
Traverse({
Expand All @@ -48,13 +48,12 @@ Collect Leaf Nodes
Replace Negative Numbers
------------------------
var sys = require('sys');
var Traverse = require('traverse').Traverse;
var Traverse = require('traverse');

var fixed = Traverse([
5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 }
]).modify(function (x) {
if (x < 0) this.update(x + 128);
}).get()
var numbers = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
var fixed = Traverse.map(numbers, function (x) {
if (typeof x == 'number' && x < 0) this.update(x + 128);
});
sys.puts(sys.inspect(fixed));

/* Output:
Expand Down Expand Up @@ -83,19 +82,19 @@ structure may be JSON-ified. The functions are also collected for some other
use.

var sys = require('sys');
var Traverse = require('traverse').Traverse;
var Traverse = require('traverse');

var id = 54;
var callbacks = {};
var obj = { moo : function () {}, foo : [2,3,4, function () {}] };

var scrubbed = Traverse(obj).modify(function (x) {
if (x instanceof Function) {
var scrubbed = Traverse.map(obj, function (x) {
if (typeof x == 'function') {
callbacks[id] = { id : id, f : x, path : this.path };
this.update('[Function]');
id++;
}
}).get();
});

sys.puts(JSON.stringify(scrubbed));
sys.puts(sys.inspect(callbacks));
Expand Down
4 changes: 2 additions & 2 deletions test/negative.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ var sys = require('sys');

exports['negative update test'] = function (assert) {
var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
var fixed = Traverse(obj).map(function (x) {
var fixed = Traverse.map(obj, function (x) {
if (x < 0) this.update(x + 128);
}).value;
});

assert.equal(
sys.inspect(fixed),
Expand Down

0 comments on commit 5aa3f84

Please sign in to comment.