{"id":15743685,"url":"https://github.com/doowb/base-tree","last_synced_at":"2025-03-13T10:30:47.867Z","repository":{"id":65990612,"uuid":"45997421","full_name":"doowb/base-tree","owner":"doowb","description":"Add a tree method to generate a hierarchical tree structure representing nested applications and child objects.","archived":false,"fork":false,"pushed_at":"2016-01-14T18:16:26.000Z","size":21,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-11T04:00:48.262Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/doowb.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}},"created_at":"2015-11-11T17:22:21.000Z","updated_at":"2021-04-12T22:04:52.000Z","dependencies_parsed_at":"2023-03-10T17:00:46.202Z","dependency_job_id":null,"html_url":"https://github.com/doowb/base-tree","commit_stats":{"total_commits":31,"total_committers":1,"mean_commits":31.0,"dds":0.0,"last_synced_commit":"32f9fd3015460512a5f4013990048827329146ee"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fbase-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fbase-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fbase-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doowb%2Fbase-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doowb","download_url":"https://codeload.github.com/doowb/base-tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221360669,"owners_count":16805034,"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":[],"created_at":"2024-10-04T03:21:02.233Z","updated_at":"2024-10-24T23:21:30.075Z","avatar_url":"https://github.com/doowb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# base-tree [![NPM version](https://img.shields.io/npm/v/base-tree.svg)](https://www.npmjs.com/package/base-tree) [![Build Status](https://img.shields.io/travis/doowb/base-tree.svg)](https://travis-ci.org/doowb/base-tree)\n\n\u003e Add a tree method to generate a hierarchical tree structure representing nested applications and child objects.\n\n## Install\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm i base-tree --save\n```\n\n## Usage\n\n```js\nvar tree = require('base-tree');\n```\n\n## API\n\n### [.tree](index.js#L40)\nCreates a `.tree` method on `app` that will recursively generate a tree of nodes specified by the `names` option passed in.\n\n\n**Params**\n\n* `options` **{Object}**: Options to use in `.tree` method    \n* `options.names` **{String|Array}**: Names of the collection objects to look for child nodes.    \n* `options.method` **{String}**: Optional method names defined on the `app`. Defaults to `tree`.    \n* `options.tree` **{Function}**: Optional `tree` function to use to generate the node or tree of nodes for the current app. Takes `app` and `options` as parameters.    \n* `options.getLabel` **{Function}**: Get a label for the node being built. Takes `app` and `options` as parameters.    \n* `options.getMetadata` **{Function}**: Get a metadata object for the node being built. Takes `app` and `options` as parameters.    \n* `returns` **{Function}**: plugin  \n\n**Example**\n\n\n\n```js\nvar app = new Base();\napp.use(tree({names: 'children'}));\n\napp.children = {};\napp.children.one = new Base();\napp.children.two = new Base();\napp.children.three = new Base();\n\nconsole.log(app.tree());\nconsole.log(archy(app.tree()));\n```\n\n\n### [options.tree](index.js#L78)\nDefault tree building function. Gets the label and metadata properties for the current `app` and recursively generates the child nodes and child trees if possible.\n\n\nThis method may be overriden by passing a `.tree` function on options.\n\n**Params**\n\n* `app` **{Object}**: Current application to build a node and tree from.    \n* `options` **{Object}**: Options used to control how the `label` and `metadata` properties are retreived.    \n* `returns` **{Object}**: Generated node containing `label`, `metadata`, and `nodes` properties for current segment of a tree.  \n\n\n\n### [options.getLabel](index.js#L124)\n\nFigure out a label to add for a node in the tree.\n\n**Params**\n\n* `app` **{Object}**: Current node/app being iterated over    \n* `options` **{Object}**: Pass `getLabel` on options to handle yourself.    \n* `returns` **{String}**: label to be shown  \n\n\n\n### [options.getMetadata](index.js#L141)\n\nAdditional metadata that should be added to a node\n\n**Params**\n\n* `app` **{Object}**: Current node/app being iterated over    \n* `options` **{Object}**: Pass `getMetadata` on options to handle yourself.    \n* `returns` **{Object}**: metadata object to add to node  \n\n\n\n\n## Running Example\n\nClone the repository, install dependencies and run the example with `node`.\n\n```sh\n$ git clone https://github.com/doowb/base-tree\n$ cd base-tree\n$ npm install\n$ node example.js\n```\n\nThe example will output the raw object and a formatted tree structure using [archy][]\n\n![image](https://cloud.githubusercontent.com/assets/995160/11600862/6d97b04e-9a9d-11e5-983d-57b47cd13c75.png)\n\n## Related projects\n* [base-methods](https://www.npmjs.com/package/base-methods): base-methods is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://www.npmjs.com/package/base-methods) | [homepage](https://github.com/jonschlinkert/base-methods)\n* [use](https://www.npmjs.com/package/use): Easily add plugin support to your node.js application. | [homepage](https://github.com/jonschlinkert/use)\n\n## Running tests\nInstall dev dependencies:\n\n```sh\n$ npm i -d \u0026\u0026 npm test\n```\n\n## Contributing\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/doowb/base-tree/issues/new).\n\n## Author\n**Brian Woodward**\n\n+ [github/doowb](https://github.com/doowb)\n+ [twitter/doowb](http://twitter.com/doowb)\n\n## License\nCopyright © 2016 [Brian Woodward](https://github.com/doowb)\nReleased under the MIT license.\n\n***\n\n_This file was generated by [verb](https://github.com/verbose/verb) on January 14, 2016._\n\n[archy]: https://github.com/substack/node-archy\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fbase-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoowb%2Fbase-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoowb%2Fbase-tree/lists"}