https://github.com/ifakejs/tree-path
Get a tree full path by the given condition.
https://github.com/ifakejs/tree-path
breadcrumb search-tree tree tree-path tree-structure typescript
Last synced: 11 months ago
JSON representation
Get a tree full path by the given condition.
- Host: GitHub
- URL: https://github.com/ifakejs/tree-path
- Owner: ifakejs
- License: mit
- Created: 2020-11-25T02:04:09.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T16:39:10.000Z (over 3 years ago)
- Last Synced: 2025-06-06T19:57:49.020Z (12 months ago)
- Topics: breadcrumb, search-tree, tree, tree-path, tree-structure, typescript
- Language: TypeScript
- Homepage:
- Size: 512 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Welcome to @ifake/tree-path đ

[](https://codecov.io/gh/ifakejs/tree-path)

[](https://github.com/ifakejs/tree-path/blob/master/LICENSE)

> Get tree path by the given condition.
English | [įŽäŊ䏿](https://github.com/ifakejs/tree-path/blob/master/README.zh-CN.md)
### đ [Homepage](https://github.com/ifakejs/tree-path)
## Install
```sh
npm install @ifake/tree-path -S
# or
yarn add @ifake/tree-path -S
```
## Usage
- Browser
```js
// We expose a global variable that can be used directly in the browser.
const { treePath } = window.IFakeTP
```
- ES6 Module
```js
import { treePath } from '@ifake/tree-path'
```
- CommonJs
```js
const { treePath } = require('@ifake/tree-path')
```
## API
#### **treePath(TreePath)**
```ts
export interface TreePath {
tree: Tree
childrenKey?: string
breakCondition: BreakCondition
}
```
- **tree**
Receive an array of object data.
- **childrenKey**
Custom property values, default is `children`
- **breakCondition**
Receives a real-time value from inside the function, defines conditions based on the value and returns a boolean value.
## Example
```js
const sourceData = [
{
id: 1,
child: [
{
id: '1-1'
},
{
id: '1-2',
child: [
{
id: '1-2-1'
}
]
}
]
},
{
id: 2
}
]
const result = treePath({
tree: sourceData,
childrenKey: 'child',
breakCondition: treeNode => treeNode.id === '1-2-1'
})
// The value should be:
[
{
id: 1,
child: [...]
},
{
id: '1-2',
child: [...]
},
{
id: '1-2-1'
}
]
```
## Run tests
```sh
yarn run test
```
## Author
đ¤ **biyuqiwan@163.com**
* Website: http://loadingmore.com
* Github: [@BiYuqi](https://github.com/BiYuqi)
## đ¤ Contributing
Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/ifakejs/tree-path/issues).
## đ License
Copyright Š 2020 [biyuqiwan@163.com](https://github.com/BiYuqi).
This project is [MIT](https://github.com/ifakejs/tree-path/blob/master/LICENSE) licensed.
***
_This README was generated with â¤ī¸ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_