{"id":20390663,"url":"https://github.com/dizmo/functions-json2tree","last_synced_at":"2025-03-05T00:12:43.638Z","repository":{"id":46987559,"uuid":"156709690","full_name":"dizmo/functions-json2tree","owner":"dizmo","description":"dizmoFun: JSON to tree mapper","archived":false,"fork":false,"pushed_at":"2023-10-18T13:42:31.000Z","size":1022,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-16T02:45:31.640Z","etag":null,"topics":["dizmo","function","javascript","json","library","mapper","tree","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dizmo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-08T13:16:40.000Z","updated_at":"2022-11-16T19:00:35.000Z","dependencies_parsed_at":"2023-02-08T12:30:25.710Z","dependency_job_id":"6baede3f-de62-40b7-aa4e-439a099dba1f","html_url":"https://github.com/dizmo/functions-json2tree","commit_stats":{"total_commits":34,"total_committers":1,"mean_commits":34.0,"dds":0.0,"last_synced_commit":"6ba80f31bc2905002262ce90af2e2de15b12f729"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dizmo%2Ffunctions-json2tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dizmo%2Ffunctions-json2tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dizmo%2Ffunctions-json2tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dizmo%2Ffunctions-json2tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dizmo","download_url":"https://codeload.github.com/dizmo/functions-json2tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241940579,"owners_count":20045883,"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":["dizmo","function","javascript","json","library","mapper","tree","typescript"],"created_at":"2024-11-15T03:26:11.535Z","updated_at":"2025-03-05T00:12:43.610Z","avatar_url":"https://github.com/dizmo.png","language":"TypeScript","readme":"[![NPM version](https://badge.fury.io/js/%40dizmo%2Ffunctions-json2tree.svg)](https://npmjs.org/package/@dizmo/functions-json2tree)\n[![Build Status](https://travis-ci.com/dizmo/functions-json2tree.svg?branch=master)](https://travis-ci.com/dizmo/functions-json2tree)\n[![Coverage Status](https://coveralls.io/repos/github/dizmo/functions-json2tree/badge.svg?branch=master)](https://coveralls.io/github/dizmo/functions-json2tree?branch=master)\n\n# @dizmo/functions-json2tree\n\nProvides two functions `array2tree` and `object2tree`, where:\n\n* `array2tree`: maps an array via an `apply` function, until the array is completely mapped, or `apply` returns `false`.\n\nThe array is a recursive description of a tree, where the *value* of a given node is at index `0` of the array followed *optionally* by other arrays, each containing the *name* followed by a *sub-tree* for any given sub-nodes. Each sub-tree is again yet another array according to the same recursive description.\n\n* `object2tree`: maps a JSON-like object via an `apply` function, until the object is completely mapped or `apply` returns `false`.\n\nThe object conforms to the same rules like any regular JSON or JavaScript object, with the addition that the values of nodes can be directly represented using an underscore `_` for the key value.\n\n## Usage\n\n### Install\n\n```sh\nnpm install @dizmo/functions-json2tree --save\n```\n\n### Require\n\n```javascript\nconst { array2tree, object2tree } = require('@dizmo/functions-json2tree');\n```\n\n### Examples\n\n```typescript\nimport { array2tree, object2tree } from '@dizmo/functions-json2tree';\n```\n\n```typescript\ndeclare const db: {\n    // db should set value for given path (or root)\n    set: (key: string | null, value: any) =\u003e any;\n};\n```\n\n```typescript\narray2tree(\"path/to/a-node\", [\n    \"α\"\n], db.set);\narray2tree(\"path/to/b-node\", [\n    \"β\", [\"i\", [0]], [\"j\", [1]], [\"k\", [2]]\n], db.set);\narray2tree(\"path/to/c-node\", [\n    \"γ\", [\"x\", [\"ξ\", [\"y\", [\"υ\", [\"z\", [\"ζ\"]]]]]]\n], db.set);\n```\n\n```typescript\nobject2tree(\"path/to/a-node\", {\n    _: \"α\"\n}, db.set);\nobject2tree(\"path/to/b-node\", {\n    _: \"β\", i: 0, j: 1, k: 2\n}, db.set);\nobject2tree(\"path/to/c-node\", {\n    _: \"γ\", x: {_: \"ξ\", y: {_: \"υ\", z: \"ζ\"}}\n}, db.set);\n```\n\n## Development\n\n### Clean\n\n```sh\nnpm run clean\n```\n\n### Build\n\n```sh\nnpm run build\n```\n\n#### without linting and cleaning:\n\n```sh\nnpm run -- build --no-lint --no-clean\n```\n\n#### with UMD bundling (incl. minimization):\n\n```sh\nnpm run -- build --prepack\n```\n\n#### with UMD bundling (excl. minimization):\n\n```sh\nnpm run -- build --prepack --no-minify\n```\n\n### Lint\n\n```sh\nnpm run lint\n```\n\n#### with auto-fixing:\n\n```sh\nnpm run -- lint --fix\n```\n\n### Test\n\n```sh\nnpm run test\n```\n\n#### without linting, cleaning and (re-)building:\n\n```sh\nnpm run -- test --no-lint --no-clean --no-build\n```\n\n### Cover\n\n```sh\nnpm run cover\n```\n\n#### without linting, cleaning and (re-)building:\n\n```sh\nnpm run -- cover --no-lint --no-clean --no-build\n```\n\n## Documentation\n\n```sh\nnpm run docs\n```\n\n## Publish\n\n```sh\nnpm publish\n```\n\n#### initially (if public):\n\n```sh\nnpm publish --access=public\n```\n\n## Copyright\n\n © 2020 [dizmo AG](http://dizmo.com/), Switzerland\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdizmo%2Ffunctions-json2tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdizmo%2Ffunctions-json2tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdizmo%2Ffunctions-json2tree/lists"}