multi-vector

easily iterate and restructure deeply nested trees

Usage no npm install needed!

<script type="module">
  import multiVector from 'https://cdn.skypack.dev/multi-vector';
</script>

README

multi-vector

easily iterate and restructure deeply nested trees

Build Status Coverage Status Code Climate Dependency Status devDependency Status

NPM

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