ns2js
v2.1.0
Published
Convert Nested Set to JavaScript array of roots of nested set
Readme
Nested Set to JavaScript object converter.
ns2js is converter from nested set (array of objects that have right and left key fields) to JavaScript array of objects, each of which is root of nested set and contains children field.
Note: this converter usable only with sorted by left key array of objects.
Usage
Add converter to project
$ npm install --save ns2jsUse in your code
Example:
const converter = require('ns2js');
const Categories = require('../collections/Categories');
Categories.orderBy('lft').fetch().then((ns) => {
let result = converter(ns, {
leftAttribute: 'lft',
rightAttribute: 'rgt'
});
console.log(result);
});See test.js for more information.
