{"id":29222732,"url":"https://github.com/lambdalisue/deno-ui-treeutil","last_synced_at":"2026-05-10T05:07:23.312Z","repository":{"id":302345552,"uuid":"1012125798","full_name":"lambdalisue/deno-ui-treeutil","owner":"lambdalisue","description":"A tree data structure utility library for Deno, providing immutable tree operations and customizable rendering capabilities.","archived":false,"fork":false,"pushed_at":"2025-07-01T21:24:13.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-01T22:26:13.346Z","etag":null,"topics":["deno","javascript","tree","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/lambdalisue.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,"zenodo":null},"funding":{"github":"lambdalisue"}},"created_at":"2025-07-01T21:18:08.000Z","updated_at":"2025-07-01T21:53:40.000Z","dependencies_parsed_at":"2025-07-01T22:36:47.748Z","dependency_job_id":null,"html_url":"https://github.com/lambdalisue/deno-ui-treeutil","commit_stats":null,"previous_names":["lambdalisue/deno-ui-treeutil"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/lambdalisue/deno-ui-treeutil","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-ui-treeutil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-ui-treeutil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-ui-treeutil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-ui-treeutil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lambdalisue","download_url":"https://codeload.github.com/lambdalisue/deno-ui-treeutil/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-ui-treeutil/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263256537,"owners_count":23438260,"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":["deno","javascript","tree","typescript"],"created_at":"2025-07-03T04:01:58.871Z","updated_at":"2026-05-10T05:07:23.268Z","avatar_url":"https://github.com/lambdalisue.png","language":"TypeScript","funding_links":["https://github.com/sponsors/lambdalisue"],"categories":[],"sub_categories":[],"readme":"# deno-ui-treeutil\n\n[![JSR](https://jsr.io/badges/@lambdalisue/ui-treeutil)](https://jsr.io/@lambdalisue/ui-treeutil)\n[![Test](https://github.com/lambdalisue/deno-ui-treeutil/actions/workflows/test.yml/badge.svg)](https://github.com/lambdalisue/deno-ui-treeutil/actions/workflows/test.yml)\n\nA tree data structure utility library for Deno, providing immutable tree\noperations and customizable rendering capabilities.\n\n## Features\n\n- 🌳 **Immutable tree operations** - All operations return new trees without\n  modifying the original\n- 📁 **Expand/collapse nodes** - Built-in support for collapsible tree branches\n- 🎨 **Customizable rendering** - Flexible tree rendering with configurable\n  symbols and indentation\n- 🔍 **Visibility management** - Get visible items based on collapsed state\n- 📝 **Type-safe** - Full TypeScript support with comprehensive type guards\n- 🧪 **Well-tested** - Extensive test coverage with BDD-style tests\n\n## Installation\n\n```bash\ndeno add @lambdalisue/ui-treeutil\n```\n\n## Usage\n\n### Basic Tree Structure\n\n```typescript\nimport {\n  collapseNode,\n  expandNode,\n  getVisibleItems,\n  type Tree,\n} from \"@lambdalisue/ui-treeutil\";\n\n// Create a tree structure\nconst tree: Tree = {\n  root: {\n    label: \"Root\",\n    value: \"root\",\n    children: [\n      {\n        label: \"Folder 1\",\n        value: \"folder1\",\n        children: [\n          { label: \"File 1\", value: \"file1\" },\n          { label: \"File 2\", value: \"file2\" },\n        ],\n        collapsed: false,\n      },\n      { label: \"File 3\", value: \"file3\" },\n    ],\n  },\n};\n\n// Collapse a node\nconst collapsedTree = collapseNode(tree, [\"folder1\"]);\n\n// Expand a node\nconst expandedTree = expandNode(collapsedTree, [\"folder1\"]);\n\n// Get visible items (excludes children of collapsed nodes)\nconst visibleItems = getVisibleItems(tree);\n```\n\n### Rendering Trees\n\n```typescript\nimport {\n  DefaultRenderer,\n  getVisibleItems,\n  type Tree,\n} from \"@lambdalisue/ui-treeutil\";\n\n// Assume we have a tree from the previous example\nconst tree: Tree = {\n  root: {\n    label: \"Root\",\n    value: \"root\",\n    children: [\n      {\n        label: \"Folder 1\",\n        value: \"folder1\",\n        children: [\n          { label: \"File 1\", value: \"file1\" },\n          { label: \"File 2\", value: \"file2\" },\n        ],\n        collapsed: false,\n      },\n      { label: \"File 3\", value: \"file3\" },\n    ],\n  },\n};\n\n// Create a renderer with default options\nconst renderer = new DefaultRenderer();\n\n// Get visible items and render them\nconst items = getVisibleItems(tree);\nconst lines = renderer.render(items);\n\nconsole.log(lines.join(\"\\n\"));\n// Output:\n// Root\n// |- Folder 1\n//  |  File 1\n//  |  File 2\n// |  File 3\n```\n\n### Custom Rendering\n\n```typescript\nimport {\n  DefaultRenderer,\n  getVisibleItems,\n  type Tree,\n  type TreeBranchItem,\n} from \"@lambdalisue/ui-treeutil\";\n\n// Using the same tree structure\nconst tree: Tree = {\n  root: {\n    label: \"Root\",\n    value: \"root\",\n    children: [\n      {\n        label: \"Folder 1\",\n        value: \"folder1\",\n        children: [\n          { label: \"File 1\", value: \"file1\" },\n          { label: \"File 2\", value: \"file2\" },\n        ],\n        collapsed: false,\n      },\n      { label: \"File 3\", value: \"file3\" },\n    ],\n  },\n};\n\nconst customRenderer = new DefaultRenderer({\n  indent: \"  \",\n  rootSymbol: \"🌳 \",\n  leafSymbol: \"📄 \",\n  branchSymbol: (item: TreeBranchItem) =\u003e item.collapsed ? \"📁 \" : \"📂 \",\n});\n\nconst items = getVisibleItems(tree);\nconst lines = customRenderer.render(items);\n// Output:\n// 🌳 Root\n// 📂 Folder 1\n//   📄 File 1\n//   📄 File 2\n// 📄 File 3\n```\n\n## API Reference\n\n### Types\n\n#### `Tree`\n\nThe root container for a tree structure.\n\n#### `TreeNode`\n\nA node in the tree, can be either a `TreeLeaf` or `TreeBranch`.\n\n#### `TreeLeaf`\n\nA terminal node with no children.\n\n#### `TreeBranch`\n\nA node that can contain child nodes and may be collapsed.\n\n#### `TreeItem`\n\nA flattened representation of a tree node used for rendering.\n\n### Functions\n\n#### `expandNode(tree, path)`\n\nExpands a collapsed node at the specified path.\n\n#### `collapseNode(tree, path)`\n\nCollapses an expanded node at the specified path.\n\n#### `getVisibleItems(tree)`\n\nReturns all visible items in the tree as a flat array, excluding children of\ncollapsed nodes.\n\n### Type Guards\n\n- `isTree(x)` - Check if a value is a valid Tree\n- `isTreeNode(x)` - Check if a value is a valid TreeNode\n- `isTreeLeaf(x)` - Check if a value is a valid TreeLeaf\n- `isTreeBranch(x)` - Check if a value is a valid TreeBranch\n- `isTreeItem(x)` - Check if a value is a valid TreeItem\n\n### Renderer\n\n#### `DefaultRenderer`\n\nA customizable renderer for tree items.\n\n**Options:**\n\n- `depth` - Function to calculate indentation depth (default: based on path\n  length)\n- `indent` - String used for indentation (default: single space)\n- `rootSymbol` - Symbol for root items (default: empty string)\n- `leafSymbol` - Symbol for leaf nodes (default: \"| \")\n- `branchSymbol` - Symbol for branch nodes (default: collapsed ? \"|+ \" : \"|- \")\n\n## License\n\nMIT License - see [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flambdalisue%2Fdeno-ui-treeutil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flambdalisue%2Fdeno-ui-treeutil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flambdalisue%2Fdeno-ui-treeutil/lists"}