0.1.0 • Published 5 years ago

data-structure-conversion v0.1.0

Weekly downloads
6
License
ISC
Repository
github
Last release
5 years ago

Install

$ npm install data-structure-conversion

Usage

const { list2tree } = require('data-structure-conversion');
const rawList = [
  { id: 1 },
  { id: 2, pid: 1 },
  { id: 3, pid: 2 },
  { id: 4 }
];

list2tree(rawList);
//=> 
[
  {
    id: 1,
    nodes: [
      {
        id: 2,
        pid: 1,
        nodes: [
          {
            id: 3,
            pid: 2
          }
        ]
      }
    ]
  },
  {
    id: 4
  }
]

API

list2tree(data[, key, parentKey])