l2t - Convert List into Tree
Elegantly Convert List into Tree
Table of Content
Get Started
Install the package
- from NPM
npm install l2t
- or from Yarn
yarn add l2t
Use with Javascript
; // with ES6 syntax:// const { listToTree } = require("lt2"); // or with CommonJS syntax: // a simple list of 6 items, three of which are childrenconst simpleList = id: "1" label: "1" id: "2" label: "2" parentId: "1" id: "3" label: "3" parentId: "1" id: "4" label: "4" id: "5" label: "5" id: "6" label: "6" parentId: "5" ; // convert the simple list into a treeconst tree = ; // output the resultconsole;
the result:
Use with Typescript (rich typing support)
;// import listToTree from "lt2"; // or with default import: // List Item interface// Tree Node interface // a simple list of 6 items, three of which are children; // convert the simple list into a tree;
this will give you the same result as the Javascript version.
Contributing
To get started see the contributing guidelines.
Unit test :
Unit test are written in Jest. Please add/edit unit test(s) for every new feature or bug fix. yarn test
to run the test suite.
Perquisites
Make sure you have:
Clone the repo
git clone https://github.com/ZibanPirate/l2t.git
Install dependencies
yarn
Run test suite
- Run once
yarn test
- Run in watch mode
yarn test --watch
- Run in watch mode with coverage report
yarn test --watch --coverage
License
Copyright (c) 2020 ZibanPirate (twitter: @ZibanPirate) Licensed under the MIT license.