{"id":13821267,"url":"https://github.com/betaWeb/NestedJS","last_synced_at":"2025-05-16T12:33:05.731Z","repository":{"id":32459103,"uuid":"134168424","full_name":"betaWeb/NestedJS","owner":"betaWeb","description":"Deal with deep nested arrays in JavaScript","archived":false,"fork":false,"pushed_at":"2022-12-09T08:40:25.000Z","size":13375,"stargazers_count":4,"open_issues_count":20,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T19:53:21.930Z","etag":null,"topics":["array-manipulations","collectr","javascript","javascript-array","javascript-library","nested","nested-structures","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/betaWeb.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-20T16:43:11.000Z","updated_at":"2024-06-03T13:27:36.000Z","dependencies_parsed_at":"2023-01-14T21:30:33.872Z","dependency_job_id":null,"html_url":"https://github.com/betaWeb/NestedJS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betaWeb%2FNestedJS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betaWeb%2FNestedJS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betaWeb%2FNestedJS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/betaWeb%2FNestedJS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/betaWeb","download_url":"https://codeload.github.com/betaWeb/NestedJS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253474208,"owners_count":21914227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array-manipulations","collectr","javascript","javascript-array","javascript-library","nested","nested-structures","nodejs"],"created_at":"2024-08-04T08:01:18.916Z","updated_at":"2025-05-16T12:33:03.454Z","avatar_url":"https://github.com/betaWeb.png","language":"JavaScript","readme":"# NestedJS\n\n[![Build Status](https://travis-ci.org/betaWeb/NestedJS.svg?branch=master)](https://travis-ci.org/betaWeb/NestedJS)\n\nThis library allows you to deal with deep nested arrays in JavaScript.\u003cbr\u003e\nNavigate into nested collections can be tricky, so NestedJS try to get it easier.\n\nYou can find a [live demo](https://codepen.io/betaweb/full/wXvvpZ/) of NestedJS here.\n\n\u003cbr\u003e\n\n## Getting started\n### Installation\n#### Browser :\nDownload the latest version of NestedJS and load the file `Nested.min.js` (on build folder) on your HTML page :\n```HTML\n    \u003cscript src=\"/path/to/Nested.min.js\"\u003e\u003c/script\u003e\n```\n\n#### NodeJS :\nYou just have to install ...\n```bash\n    # with NPM\n    $ npm install nestedjs\n\n    # with Yarn\n    $ yarn add nestedjs\n```\n\n... and load the package on your script\n```JS\nconst NestedJS = require('nestedjs')\n// OR\nimport NestedJS from 'nestedjs'\n```\n\n### Usage\n#### Instanciation\nOnce package loaded, NestedJS must ne instanciate with a nested collection.\n```JS\nconst collection = [...] // Nested data collection\nconst tree = new NestedJS(collection)\n```\n\u003e **IMPORTANT** : The property of every node's children if there are, is named `children` by default. You can change the name with the option `children_key`.\n\n\u003cbr\u003e\n\nThe created instance transform the collection and add several properties and methods to each collection's node :\n#### Properties\n - `__nodeid` : this property is unique and allows you to retrieve a specific node\n - `__parentid` : tag the parent node id of a node if exists, null otherwise\n - `__rootid` : tag the root node id of a node if exists, null otherwise\n - `__previd` : tag the previous node id of a node if exists, null otherwise\n - `__nextid` : tag the next node id of a node if exists, null otherwise\n - `__depth` : tag the node depth (0 to n)\n\n \u003e To know the added properties on each node you must debug your collection, or you can simply browse it with a recursive loop.\n\n#### Methods\nYou can retrieve a node by his unique id :\n```JS\n    const node = tree.retrieveNode(/* __nodeid node unique id */)\n```\n\nThis will returns a node which is an instance of the NestedJS's `Node` class. This class has several methods :\n\n- returns original properties of the node :\n```JS\n    node.properties\n```\n\n- returns node unique id :\n```JS\n    node.getId()\n```\n\n- returns node parent unique id :\n```JS\n    node.getParentId()\n```\n\n- returns next node unique id :\n```JS\n    node.getNextId()\n```\n\n- returns previous node unique id :\n```JS\n    node.getPreviousId()\n```\n\n- check if node property exists :\n```JS\n    node.hasProperty(key)\n```\n\n- returns node property if exists, defaultValue otherwise :\n```JS\n    node.getProperty(key, defaultValue)\n```\n\n- set node's property :\n```JS\n    node.setProperty(key, value)\n```\n\n- returns an array of previous nodes if exists, null otherwise :\n```JS\n    node.previousNodes()\n```\n\n- returns previous node if exists, null otherwise :\n```JS\n    node.previousNode()\n```\n\n- returns true if the node has a predecessor, false otherwise :\n```JS\n    node.hasPreviousNode()\n```\n\n- returns an array of next nodes if exists, null otherwise :\n```JS\n    node.nextNodes()\n```\n\n- returns next node if exists, null otherwise :\n```JS\n    node.nextNode()\n```\n\n- returns true if the node has a successor, false otherwise :\n```JS\n    node.hasNextNode()\n```\n\n- returns an array of siblings nodes if exists, null otherwise\n```JS\n    node.siblingsNodes()\n```\n\n- returns an array of child nodes :\n```JS\n    node.childNodes()\n```\n\n- returns node's first child if it has, null otherwise :\n```JS\n    node.firstChild()\n```\n\n- returns node's last child if is has, null otherwise :\n```JS\n    node.lastChild()\n```\n\n- returns node's child by index if it has, null otherwise :\n```JS\n    node.nthChild()\n```\n\n- return true if the node has children, false otherwise :\n```JS\n    node.hasChildNodes()\n```\n\n- returns parent node if exists, null otherwise :\n```JS\n    node.parentNode()\n```\n\n- returns true if the node has an ancestor, false otherwise :\n```JS\n    node.hasParentNode()\n```\n\n- returns root node if exists, null otherwise :\n```JS\n    node.rootNode()\n```\n\n- returns true if the node has a root node, false otherwise :\n```JS\n    node.hasRootNode()\n```\n\n- returns current node breadcrumb :\n```JS\n    node.breadcrumb()\n```\n\n- returns NestedJS instance :\n```JS\n    node.getTree()\n```\n\n- returns node depth :\n```JS\n    node.depth()\n```\n\n\u003e Each node original properties are preserved and are transferred as properties of the NestedJS's `Node` class.\n\nYou also retrieve one or several nodes by a key/value couple search :\n```JS\nconst nodes = tree.retrieveNodesBy('name', 'lorem')\n```","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FbetaWeb%2FNestedJS","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FbetaWeb%2FNestedJS","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FbetaWeb%2FNestedJS/lists"}