Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

list-to-tree-lite

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

list-to-tree-lite

convert list to tree-list

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status

list-to-tree-lite

A simple function converts a flat-list of objects with id, parent and children to a tree-list of objects.
without any dependencies.

[{
    id: 6,
    any: 'opps'
}, {
    id: 2,
    parent: 5,
    any: 'foo',
}, {
    id: 1,
    parent: 2,
    any: 'bar'
}, {
    id: 5,
    any: 'hello'
}, {
    id: 3,
    parent: 2,
    any: 'other'
}]

to

[{
    id: 6,
    any: 'opps',
    children: []
}, {
    id: 5,
    any: 'hello',
    children: [{
        id: 2,
        parent: 5,
        any: 'foo',
        children: [{
            id: 1,
            parent: 2,
            any: 'bar',
            children: []
        }, {
            id: 3,
            parent: 2,
            any: 'other',
            children: []
        }]
    }]
}]

#Usage
listToTree(list[, options])

options.idKey
the id key of the item object, default id

options.parentKey
the parent key of the item object, default parent

options.childrenKey
the children key of the item object, default children

#Install npm install list-to-tree-lite --save

#Test
npm run test

#License
MIT:http://william17.mit-license.org

Keywords

FAQs

Package last updated on 14 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc