0.0.2 • Published 9 years ago
multi-vector v0.0.2
multi-vector
easily iterate and restructure deeply nested trees
Usage
var MultiVector = require('multi-vector');
var mv = new MultiVector('a', 'b', 'c'); // list the index names
mv.set({a: 'foo', b: 2, c: 3}, 'hello');
mv.set({a: 'foo', b: 2, c: 4}, 'howdy');
mv.get({a: 'foo', b: 2, c: 3});
//=> 'hello'
function logArgs() {
console.log(Array.prototoype.join.call(arguments, ','));
}
// Iterate the trees
mv.forEach(logArgs);
// 'hello', 'foo', 2, 3
// 'howdy', 'foo', 2, 4
mv.forEach(logArgs, ['c', 'a', 'b']); // custom ordering of callback arguments
// 'hello', 3, 'foo', 2
// 'howdy', 4, 'foo', 2
mv.export();
/*{
'foo': {
'2': {
'3': 'hello',
'4': 'howdy'
}
}
}*/
mv.export(['c', 'a', 'b']); // reshape or pivot the exported data
/*{
'3': {
'foo': {
'2': 'hello'
}
},
'4': {
'foo': {
'2': 'howdy'
}
}
}*/
License
MIT © James Talmage