-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
date.js
35 lines (27 loc) · 780 Bytes
/
date.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var assert = require('assert');
var Traverse = require('traverse');
exports.dateEach = function () {
var obj = { x : new Date, y : 10, z : 5 };
var counts = {};
Traverse(obj).forEach(function (node) {
var t = (node instanceof Date && 'Date') || typeof node;
counts[t] = (counts[t] || 0) + 1;
});
assert.deepEqual(counts, {
object : 1,
Date : 1,
number : 2,
});
};
exports.dateMap = function () {
var obj = { x : new Date, y : 10, z : 5 };
var res = Traverse(obj).map(function (node) {
if (typeof node === 'number') this.update(node + 100);
});
assert.ok(obj.x !== res.x);
assert.deepEqual(res, {
x : obj.x,
y : 110,
z : 105,
});
};