Sha256: e5706543fc0604124d492c34dfb1bf00f7f2713c12fe20bd73640008422df59d

Contents?: true

Size: 775 Bytes

Versions: 3

Compression:

Stored size: 775 Bytes

Contents

var assert = require('assert');
var Traverse = require('../');

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,
    });
};

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
trans-0.5.10 template/node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/node_modules/tap/node_modules/runforcover/node_modules/bunker/node_modules/burrito/node_modules/traverse/test/date.js
trans-0.5.9 template/node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/node_modules/tap/node_modules/runforcover/node_modules/bunker/node_modules/burrito/node_modules/traverse/test/date.js
holmes-0.0.1 lib/holmes/node_modules/detective/node_modules/burrito/node_modules/traverse/test/date.js