Socket
Socket
Sign inDemoInstall

flat-to-nested

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    flat-to-nested

Convert a hierarchy from flat to nested representation.


Version published
Weekly downloads
1.7K
increased by30.38%
Maintainers
1
Install size
14.6 kB
Created
Weekly downloads
 

Readme

Source

flat-to-nested

Convert a hierarchy from flat to nested representation.

Build Status

Example

var FlatToNested, flatToNested, flat;

FlatToNested = require('flat-to-nested');
flatToNested = new FlatToNested( /* can take a config object to use other property names */ );

flat = [
	{id: 111, parent: 11},
	{id: 11, parent: 1},
	{id: 12, parent: 1},
	{id: 1}
];

var nested = flatToNested.convert(flat);
console.log(nested);

//	{
//		id: 1,
//		children: [
//			{
//				id: 11,
//				children: [
//					{
//						id: 111
//					}
//				]
//			},
//			{
//				id: 12
//			}
//		]
//	}

Configuration

The constructor accepts an optional object with some or all of these properties:

flatToNested = new FlatToNested({
	// The name of the property with the node id in the flat representation
	id: 'id',
	// The name of the property with the parent node id in the flat representation
	parent: 'parent',
	// The name of the property that will hold the children nodes in the nested representation
	children: 'children'
}});

Contributing

Setup

Fork this repository and run npm install on the project root folder to make sure you have all project dependencies installed.

Code Linting

Run npm run lint

This will check both source and tests for code correctness and style compliance.

Running Tests

Run npm test

Keywords

FAQs

Last updated on 26 Feb 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc