UNPKG

775 BJavaScriptView Raw
1var assert = require('assert');
2var Traverse = require('../');
3
4exports.dateEach = function () {
5 var obj = { x : new Date, y : 10, z : 5 };
6
7 var counts = {};
8
9 Traverse(obj).forEach(function (node) {
10 var t = (node instanceof Date && 'Date') || typeof node;
11 counts[t] = (counts[t] || 0) + 1;
12 });
13
14 assert.deepEqual(counts, {
15 object : 1,
16 Date : 1,
17 number : 2,
18 });
19};
20
21exports.dateMap = function () {
22 var obj = { x : new Date, y : 10, z : 5 };
23
24 var res = Traverse(obj).map(function (node) {
25 if (typeof node === 'number') this.update(node + 100);
26 });
27
28 assert.ok(obj.x !== res.x);
29 assert.deepEqual(res, {
30 x : obj.x,
31 y : 110,
32 z : 105,
33 });
34};
35