{"id":16009767,"url":"https://github.com/muratcatal/tree-data-util","last_synced_at":"2025-03-18T02:32:21.358Z","repository":{"id":57379497,"uuid":"115415464","full_name":"muratcatal/tree-data-util","owner":"muratcatal","description":"JSON tree data util functions","archived":false,"fork":false,"pushed_at":"2018-11-05T13:35:53.000Z","size":78,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T06:21:02.361Z","etag":null,"topics":["find","javascript","json","parent","parents","tree","tree-structure"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/muratcatal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-26T11:16:51.000Z","updated_at":"2021-06-19T02:56:53.000Z","dependencies_parsed_at":"2022-09-02T20:41:28.396Z","dependency_job_id":null,"html_url":"https://github.com/muratcatal/tree-data-util","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/muratcatal%2Ftree-data-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muratcatal%2Ftree-data-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muratcatal%2Ftree-data-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muratcatal%2Ftree-data-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/muratcatal","download_url":"https://codeload.github.com/muratcatal/tree-data-util/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243894541,"owners_count":20365048,"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":["find","javascript","json","parent","parents","tree","tree-structure"],"created_at":"2024-10-08T13:04:08.309Z","updated_at":"2025-03-18T02:32:21.031Z","avatar_url":"https://github.com/muratcatal.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TREE DATA UTIL\n----\nThis library help you search for a parent of your node, or get all parents of your node in a tree structure. It has zero-dependency.\n\n# How to install\n----\n##### Using npm\n---\n```\n$ npm i --save tree-data-util\n```\n\n##### Using yarn\n---\n```\n $ yarn add tree-data-util\n```\n\n##### Compiling source code\n---\n- Download src code from github\n- Open your cli and type\n```\n$ npm run build\n```\nor \n```\n$ yarn run build\n```\n- Get file in dist folder and referance it in your application\n# How to use\n----\n#### With default configuration file\n```javascript\nimport {findParent,findAllParents} from 'tree-data-util'\n\nlet data = [\n  {\n    \"id\": \"5a42327d9d7b2555c54e94c1\",\n    \"name\": \"Carney Livingston\",\n    \"children\": [\n      {\n        \"id\": \"5a42327d6c3ec84516e9a01e\",\n        \"name\": \"Francesca Rice\",\n        \"children\": [\n          {\n            \"id\": \"5a42327df5419a1796e7b43e\",\n            \"name\": \"Gladys Kramer\"\n          },\n          {\n            \"id\": \"5a42327d4263c504d740360d\",\n            \"name\": \"Kerry Pacheco\"\n          }\n        ]\n      },\n      {\n        \"id\": \"5a42327d0f8a5a94c5ff93d2\",\n        \"name\": \"Acosta Perez\",\n        \"children\": [\n          {\n            \"id\": \"5a42327d1c907390edbae7d9\",\n            \"name\": \"Mcfadden Sloan\"\n          }\n        ]\n      }\n    ]\n  }\n]\n\nlet node = {\n        \"id\": \"5a42327d0f8a5a94c5ff93d2\",\n        \"name\": \"Acosta Perez\",\n        \"children\": [\n          {\n            \"id\": \"5a42327d1c907390edbae7d9\",\n            \"name\": \"Mcfadden Sloan\"\n          }\n        ]\n};\n\nconst parent = findParent(data,node,(touchedNode,myNode) =\u003e item.id === myNode.id);\nconst parents = findAllParents(data,node,(touchedNode,myNode) =\u003e item.id === myNode.id);\n```\n#### With configuration file\nTo configure findParent or findAllParents function, send configuration parameter as last element. \n```javascript\nlet data = [\n  {\n    \"id\": \"5a42375029d4c6f5578f851c\",\n    \"name\": \"Lynnette Jefferson\",\n    \"members\": [\n      {\n        \"id\": \"5a423750697fde154251384f\",\n        \"name\": \"Phillips Lawrence\",\n        \"members\": [\n          {\n            \"id\": \"5a4237509539a1f7b2eb7130\",\n            \"name\": \"Roxie Sampson\"\n          }\n        ]\n      },\n      {\n        \"id\": \"5a423750d66c2c134fa2ad20\",\n        \"name\": \"Holland Gomez\",\n        \"members\": [\n          {\n            \"id\": \"5a423750333570a106706791\",\n            \"name\": \"Clarke Lewis\"\n          }\n        ]\n      }\n    ]\n  }\n];\n\nconst config = {\n    props: {\n        children: \"members\"\n    }\n}\nconst parent = findParent(data,node,(touchedNode,myNode) =\u003e item.id === myNode.id,config);\nconst parents = findAllParents(data,node,(touchedNode,myNode) =\u003e item.id === myNode.id,config);\n```\n# OUTPUT\n----\n\u003e findParent function return parent node in your tree data\n```javascript\n/* output example of findParent */\n{\n  \"id\": \"5a42327d6c3ec84516e9a01e\",\n  \"name\": \"Francesca Rice\",\n  \"children\": [\n    {\n      \"id\": \"5a42327df5419a1796e7b43e\",\n      \"name\": \"Gladys Kramer\"\n    },\n    {\n      \"id\": \"5a42327d4263c504d740360d\",\n      \"name\": \"Kerry Pacheco\"\n    }\n  ]\n}\n```\n---\n\u003e findAllParents function will return array of all parents starts from root to last parent which means zero index will have your root node\n```javascript\n/* output example of findAllParents */\n[\n  {\n    \"id\": \"5a42327d9d7b2555c54e94c1\",\n    \"name\": \"Carney Livingston\",\n    \"children\": [\n      {\n        \"id\": \"5a42327d6c3ec84516e9a01e\",\n        \"name\": \"Francesca Rice\",\n        \"children\": [\n          {\n            \"id\": \"5a42327df5419a1796e7b43e\",\n            \"name\": \"Gladys Kramer\"\n          },\n          {\n            \"id\": \"5a42327d4263c504d740360d\",\n            \"name\": \"Kerry Pacheco\"\n          }\n        ]\n      },\n      {\n        \"id\": \"5a42327d0f8a5a94c5ff93d2\",\n        \"name\": \"Acosta Perez\",\n        \"children\": [\n          {\n            \"id\": \"5a42327d1c907390edbae7d9\",\n            \"name\": \"Mcfadden Sloan\"\n          }\n        ]\n      }\n    ]\n  },\n  {\n    \"id\": \"5a42327d6c3ec84516e9a01e\",\n    \"name\": \"Francesca Rice\",\n    \"children\": [\n      {\n        \"id\": \"5a42327df5419a1796e7b43e\",\n        \"name\": \"Gladys Kramer\"\n      },\n      {\n        \"id\": \"5a42327d4263c504d740360d\",\n        \"name\": \"Kerry Pacheco\"\n      }\n    ]\n  }\n]\n```\n# Parameter Descriptions\n----\n\u003e findParent and findAllParents functions get exactly the same parameters. The difference between them is just return types.\n\n| Parameter \t|   Type   \t| Required \t| Defaults                                \t| Description                                                                                                                                                                                                                                                                                                                                                                                \t|\n|:---------:\t|:--------:\t|----------\t|-----------------------------------------\t|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\t|\n| data      \t|   array  \t| yes      \t| -                                       \t| tree structured data in an array                                                                                                                                                                                                                                                                                                                                                           \t|\n| node      \t|   json   \t| yes      \t| -                                       \t| the node in json format you want to find parent                                                                                                                                                                                                                                                                                                                                            \t|\n| predicate \t| function \t| yes      \t| -                                       \t| function to find your node in data tree. that function will have two parameters. First parameter will be the touched node in tree and second parameter will be your searched node. ex: you want to find your node by id so that function will be like this;   (touchedNode, searchedNode) =\u003e touchedNode.id === searchedNode when this expression sets true it will return your parent \t|\n| config    \t|   json   \t| no       \t| {  props:{   children:'children'    } } \t| configuration parameter for children variables in your tree. you can configure your children variable name to be looked for in your tree by that configuration parameter. by default, functions will look for 'children' property in your tree model.                                                                                                                                      \t|\n\n# Change log\n----\nTo access change log,[please click ](./CHANGELOG.md)\n# Contributing\n----\nI'd be very happy if you feedback any issue","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuratcatal%2Ftree-data-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuratcatal%2Ftree-data-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuratcatal%2Ftree-data-util/lists"}