{"id":32255518,"url":"https://github.com/nozer/self-referential","last_synced_at":"2026-02-23T06:01:52.826Z","repository":{"id":19988863,"uuid":"23256090","full_name":"nozer/self-referential","owner":"nozer","description":"Allows a self referential collection to be converted into a nested or flat hierarchy","archived":false,"fork":false,"pushed_at":"2015-05-15T19:02:25.000Z","size":272,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-04T23:39:11.616Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/nozer.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":"2014-08-23T13:14:41.000Z","updated_at":"2023-04-11T06:23:51.000Z","dependencies_parsed_at":"2022-07-22T03:31:59.776Z","dependency_job_id":null,"html_url":"https://github.com/nozer/self-referential","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/nozer/self-referential","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nozer%2Fself-referential","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nozer%2Fself-referential/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nozer%2Fself-referential/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nozer%2Fself-referential/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nozer","download_url":"https://codeload.github.com/nozer/self-referential/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nozer%2Fself-referential/sbom","scorecard":{"id":696016,"data":{"date":"2025-08-11","repo":{"name":"github.com/nozer/self-referential","commit":"4400c60ef7dc38dd7a7605d543e091522eee273f"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-22T03:43:00.272Z","repository_id":19988863,"created_at":"2025-08-22T03:43:00.272Z","updated_at":"2025-08-22T03:43:00.272Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29738515,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T04:51:08.365Z","status":"ssl_error","status_checked_at":"2026-02-23T04:49:15.865Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2025-10-22T18:46:05.620Z","updated_at":"2026-02-23T06:01:52.820Z","avatar_url":"https://github.com/nozer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"self-referential\n================\n\nAllows a self referential collection (array of objects) to be converted into a nested or flat hierarchy\n\n###Install \u0026 Require\n```\nnpm install self-referential\n\nvar selfref = require('self-referential');\n```\n\n###Examples\nImagine a table named `categories` like below where `parentId` foreign key refers to a record in the same `categories` table.\n\nid | title | parentId\n--- | --- | ---\n1 | Colors | null\n2 | Fruits | null\n3 | Meats | null\n4 | Warm Colors | 1\n5 | Cold Colors | 1\n6 | Red | 4\n7 | Orange | 4\n8 | Apple | 2\n\nWe can represent this table as an array of objects as shown below:\n\n```\nvar categories = [\n       {\n           id: 1,\n           title: 'Colors',\n           parentId: null\n       },\n       {\n           id: 2,\n           title: 'Fruits',\n           parentId: null\n       },\n       {\n           id: 3,\n           title: 'Meats',\n           parentId: null\n       },\n       {\n           id: 4,\n           title: 'Warm Colors',\n           parentId: 1\n       },\n       {\n           id: 5,\n           title: 'Cold Colors',\n           parentId: 1\n       },\n       {\n           id: 6,\n           title: 'Red',\n           parentId: 4\n       },\n       {\n           id: 7,\n           title: 'Orange',\n           parentId: 4\n       },\n       {\n           id: 8,\n           title: 'Apple',\n           parentId: 2\n       }\n   ];\n```\n\n####To Nested Hierarchy\nTo convert this to a nested hierarchy, we do:\n```\nvar cfg = {\n    selfKey: 'id',\n    parentKey: 'parentId',\n    childrenKey: 'children'\n\n    // Optional properties\n    // rootParentValues: see way below for explanation\n    // rootSelfValues : see way below for explanation\n};\nvar cats_hierarchy = selfref.toHier(cfg, categories);\n```\ncats_hierarchy has the following structure\n```\n[\n    {\n        \"id\": 1,\n        \"title\": \"Colors\",\n        \"parentId\": null,\n        \"children\": [\n            {\n                \"id\": 4,\n                \"title\": \"Warm Colors\",\n                \"parentId\": 1,\n                \"children\": [\n                    {\n                        \"id\": 6,\n                        \"title\": \"Red\",\n                        \"parentId\": 4,\n                        \"children\": []\n                    },\n                    {\n                        \"id\": 7,\n                        \"title\": \"Orange\",\n                        \"parentId\": 4,\n                        \"children\": []\n                    }\n                ]\n            },\n            {\n                \"id\": 5,\n                \"title\": \"Cold Colors\",\n                \"parentId\": 1,\n                \"children\": []\n            }\n        ]\n    },\n    {\n        \"id\": 2,\n        \"title\": \"Fruits\",\n        \"parentId\": null,\n        \"children\": [\n            {\n                \"id\": 8,\n                \"title\": \"Apple\",\n                \"parentId\": 2,\n                \"children\": []\n            }\n        ]\n    },\n    {\n        \"id\": 3,\n        \"title\": \"Meats\",\n        \"parentId\": null,\n        \"children\": []\n    }\n]\n```\n####To Flat Hierarchy\nTo convert the above hierarchy into a flat collection, but in the same order as it would be in the hierarchy, we do:\n```\nvar flat_but_in_hierarchical_order_cats = selfref.toFlatHier({childrenKey: 'children'}, cats_hierarchy);\n```\nflat_but_in_hierarchical_order_cats now has the following structure:\n```\n[\n       {\n              item: object: \u003cyour original item\u003e\n              hierPos: string: \u003cposition of item in a hierarchy such as 1.1 or 1.2.1 as in a table of contents in a book\u003e\n              depth: int: \u003cdepth of item in hierarchy, root has the value of zero\u003e\n              childCount: int: \u003cnumber of children\u003e\n       }\n       ...\n]\n```\n```\n[\n    {\n        \"item\": {\n            \"id\": 1,\n            \"title\": \"Colors\",\n            \"parentId\": null\n        },\n        \"hierPos\": \"1\",\n        \"depth\": 0,\n        \"childCount\": 2\n    },\n    {\n        \"item\": {\n            \"id\": 4,\n            \"title\": \"Warm Colors\",\n            \"parentId\": 1\n        },\n        \"hierPos\": \"1.1\",\n        \"depth\": 1,\n        \"childCount\": 2\n    },\n    {\n        \"item\": {\n            \"id\": 6,\n            \"title\": \"Red\",\n            \"parentId\": 4\n        },\n        \"hierPos\": \"1.1.1\",\n        \"depth\": 2,\n        \"childCount\": 0\n    },\n    {\n        \"item\": {\n            \"id\": 7,\n            \"title\": \"Orange\",\n            \"parentId\": 4\n        },\n        \"hierPos\": \"1.1.2\",\n        \"depth\": 2,\n        \"childCount\": 0\n    },\n    {\n        \"item\": {\n            \"id\": 5,\n            \"title\": \"Cold Colors\",\n            \"parentId\": 1\n        },\n        \"hierPos\": \"1.2\",\n        \"depth\": 1,\n        \"childCount\": 0\n    },\n    {\n        \"item\": {\n            \"id\": 2,\n            \"title\": \"Fruits\",\n            \"parentId\": null\n        },\n        \"hierPos\": \"2\",\n        \"depth\": 0,\n        \"childCount\": 1\n    },\n    {\n        \"item\": {\n            \"id\": 8,\n            \"title\": \"Apple\",\n            \"parentId\": 2\n        },\n        \"hierPos\": \"2.1\",\n        \"depth\": 1,\n        \"childCount\": 0\n    },\n    {\n        \"item\": {\n            \"id\": 3,\n            \"title\": \"Meats\",\n            \"parentId\": null\n        },\n        \"hierPos\": \"3\",\n        \"depth\": 0,\n        \"childCount\": 0\n    }\n]\n```\n####Root Elements\nFinally, to get only the root elements of our collection, we do:\n```\nvar root_cats = selfref.rootItems({selfKey: 'id', parentKey:'parentId'}, categories);\n```\nroot_cats now has the following data:\n```\n[\n    {\n        \"id\": 1,\n        \"title\": \"Colors\",\n        \"parentId\": null\n    },\n    {\n        \"id\": 2,\n        \"title\": \"Fruits\",\n        \"parentId\": null\n    },\n    {\n        \"id\": 3,\n        \"title\": \"Meats\",\n        \"parentId\": null\n    }\n]\n```\n\n###Config Parameters \u0026 Usage\nConfiguration parameter cfg can have the following properties:\n\n`selfKey`:  name of property that is uniquely identifies this record\n\n`parentKey`:  name of property that whose value refers to its parent's unique id\n\n`childrenKey`:  name of the property that the children of this model should be set to\n\n`rootParentValues`: null|string|number|array\n\u003e Sets nodes whose parentKey values you are specifying as the root nodes in hierarchy and goes from there  \n\n\n`rootSelfValues`: null|string|number|array\n\u003e Sets nodes whose selfKey values you are specifying as the root nodes in hierarchy and goes from there  \n\n\u003e if any of those rootXValues are omitted, all of items with no matching parents will be picked as root items and then\n\u003e hierarchy will be generated with them and their children.\n\n\u003e You cannot specify both rootParentValues and rootSelfValues at the same time\n\n `selfref.toHier(cfg, collectionData);` cfg must have all of the above properties (except rootParentValues)\n\n`selfref.toFlatHier(cfg, hierarchyCollection);` cfg must have `childrenKey` property only\n\n`selfref.rootItems(cfg, collectionData);` cfg must have `selfKey` and `parentKey` properties\n\n`selfref.getAncestors(cfg, collectionData, selfKeyValue)` returns ancestors of the item having the selfKey property value of selfKeyValue.  \n    cfg must have `selfKey` and `parentKey` properties\n\n`selfref.getChildren(cfg, collectionData, selfKeyValue)` returns children of the item having the selfKey property value of selfKeyValue.  \n    cfg must have `selfKey` and `parentKey` properties\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnozer%2Fself-referential","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnozer%2Fself-referential","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnozer%2Fself-referential/lists"}