operation-tree-node
Advanced tools
Comparing version 1.0.6 to 1.0.7
{ | ||
"name": "operation-tree-node", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"author": "yujinpan", | ||
@@ -14,19 +14,16 @@ "main": "dist/index.common.js", | ||
"files": [ | ||
"src", | ||
"dist/*.js", | ||
"types/**/*.d.ts" | ||
"dist", | ||
"README.md" | ||
], | ||
"scripts": { | ||
"build": "cross-env NODE_ENV=production npm run build:js && npm run build:types", | ||
"build": "cross-env NODE_ENV=production rollupx && eslint --fix dist/**/*.d.ts", | ||
"test": "karma start test/unit/karma.config.js", | ||
"build:js": "node build/build.js", | ||
"build:types": "tsc --emitDeclarationOnly && eslint --fix 'types/**/*'", | ||
"lint": "eslint --fix './**/*'" | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"core-js": "^3.x" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.6.4", | ||
"@babel/plugin-proposal-export-default-from": "^7.5.2", | ||
"@babel/preset-env": "^7.6.3", | ||
"@babel/preset-typescript": "^7.6.0", | ||
"@babel/core": "^7.12.10", | ||
"@babel/preset-typescript": "^7.13.0", | ||
"@types/jasmine": "^3.4.4", | ||
@@ -48,10 +45,3 @@ "@typescript-eslint/eslint-plugin": "^2.5.0", | ||
"prettier": "1.18.2", | ||
"rollup": "^1.13.1", | ||
"rollup-plugin-alias": "^1.5.2", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-commonjs": "^10.0.0", | ||
"rollup-plugin-json": "^4.0.0", | ||
"rollup-plugin-node-resolve": "^5.0.1", | ||
"rollup-plugin-visualizer": "^1.1.1", | ||
"terser": "^4.3.9", | ||
"rollupx": "^1.1.8", | ||
"typescript": "^3.6.4", | ||
@@ -58,0 +48,0 @@ "webpack": "^4.41.2" |
180
README.md
@@ -23,2 +23,27 @@ Operation method collection for tree node(like operation array). | ||
- `treeCheck(data, checkIds, props)` tree node check | ||
get all associated node'id by check one node. | ||
arguments: | ||
| name | type | description | | ||
| ---------- | ------------------- | --------------------- | | ||
| `data` | (same) | (same) | | ||
| `checkIds` | `number[]/string[]` | will checked node ids | | ||
| `props` | (same) | (same) | | ||
```js | ||
import { treeCheck } from "operation-tree-node"; | ||
const treeData = [{ id: 1, name: "123", children: [{ id: 2, name: "2" }] }]; | ||
const resultIds = treeCheck(treeData, [2], { | ||
id: "id", | ||
children: "children", | ||
parent: "parent" | ||
}); | ||
console.log(resultIds); | ||
// [2, 1] | ||
``` | ||
- `treeEach(data, callback, props)` tree node each(like `Array.prototype.forEach`) | ||
@@ -44,2 +69,47 @@ | ||
- `treeEachParent(data, callback, props)` tree node each parent | ||
recursive will break until callback is false. | ||
arguments: | ||
| name | type | description | | ||
| ---------- | -------------------------- | ---------------------------------------------------------- | | ||
| `data` | (same) | (same) | | ||
| `callback` | `(parent) => void/boolean` | parent: parent node, if callback false, skip parent.parent | | ||
| `props` | (same) | (same) | | ||
```js | ||
import { treeEachParent } from "operation-tree-node"; | ||
const treeData = [ | ||
{ id: 1, name: "123", children: [{ id: 2, name: "2", parent: null }] } | ||
]; | ||
treeData[0].children[0].parent = treeData[0]; | ||
const names = []; | ||
treeEachParent(treeData[0].children, parent => !!names.push(parent.name)); | ||
console.log(names); | ||
// ['123'] | ||
``` | ||
- `treeFilter(data, callback, props)` tree node filter(like `Array.prototype.filter`) | ||
get a new data instead of change source. | ||
```js | ||
import { treeFilter } from "operation-tree-node"; | ||
const treeData = [ | ||
{ id: 1, name: "1", child: [{ id: 2, name: "2" }] }, | ||
{ id: 3, name: "3" } | ||
]; | ||
const result = treeFilter(treeData, node => node.id === 2, { | ||
children: "child" | ||
}); | ||
console.log(result); | ||
// [{ id: 1, name: '1', child: [{ id: 2, name: '2' }] }] | ||
``` | ||
- `treeFind(data, callback, props)` tree node find(like `Array.prototype.find`) | ||
@@ -62,2 +132,22 @@ | ||
- `treeFind(node, callback, props)` tree node find parent | ||
```js | ||
import { treeFindParent } from "operation-tree-node"; | ||
const treeData = [ | ||
{ | ||
id: 1, | ||
name: "123", | ||
parent: null, | ||
children: [{ id: 2, name: "2", parent: null, children: [] }] | ||
} | ||
]; | ||
treeData[0].children[0].parent = treeData[0]; | ||
const find = treeFindParent(treeData[0].children[0], node => node.id === 1); | ||
console.log(find); | ||
// { id: 1, name: '123', children: ... } | ||
``` | ||
- `treeMap(data, callback, props)` tree node map(like `Array.prototype.map`) | ||
@@ -82,38 +172,2 @@ | ||
- `treeFilter(data, callback, props)` tree node filter(like `Array.prototype.filter`) | ||
get a new data instead of change source. | ||
```js | ||
import { treeFilter } from "operation-tree-node"; | ||
const treeData = [ | ||
{ id: 1, name: "1", child: [{ id: 2, name: "2" }] }, | ||
{ id: 3, name: "3" } | ||
]; | ||
const result = treeFilter(treeData, node => node.id === 2, { | ||
children: "child" | ||
}); | ||
console.log(result); | ||
// [{ id: 1, name: '1', child: [{ id: 2, name: '2' }] }] | ||
``` | ||
- `treeToFlatArray(data, callback, props)` tree to flat array | ||
get a flat array and source data structure is not change. | ||
```js | ||
import { treeToFlatArray } from "operation-tree-node"; | ||
const treeData = [{ id: 1, name: "1", children: [{ id: 2, name: "2" }] }]; | ||
const result = treeToFlatArray(treeData); | ||
console.log(result); | ||
// [ | ||
// { id: 1, name: '1', children: [{ id: 2, name: '2' }] }, | ||
// { id: 2, name: '2' } | ||
// ] | ||
``` | ||
- `treeMerge(data, callback, props)` tree node merge(same level) | ||
@@ -190,51 +244,17 @@ | ||
- `treeEachParent(data, callback, props)` tree node each parent | ||
- `treeToFlatArray(data, callback, props)` tree to flat array | ||
recursive will break until callback is false. | ||
get a flat array and source data structure is not change. | ||
arguments: | ||
| name | type | description | | ||
| ---------- | -------------------------- | ---------------------------------------------------------- | | ||
| `data` | (same) | (same) | | ||
| `callback` | `(parent) => void/boolean` | parent: parent node, if callback false, skip parent.parent | | ||
| `props` | (same) | (same) | | ||
```js | ||
import { treeEachParent } from "operation-tree-node"; | ||
import { treeToFlatArray } from "operation-tree-node"; | ||
const treeData = [ | ||
{ id: 1, name: "123", children: [{ id: 2, name: "2", parent: null }] } | ||
]; | ||
treeData[0].children[0].parent = treeData[0]; | ||
const treeData = [{ id: 1, name: "1", children: [{ id: 2, name: "2" }] }]; | ||
const names = []; | ||
treeEachParent(treeData[0].children, parent => !!names.push(parent.name)); | ||
console.log(names); | ||
// ['123'] | ||
const result = treeToFlatArray(treeData); | ||
console.log(result); | ||
// [ | ||
// { id: 1, name: '1', children: [{ id: 2, name: '2' }] }, | ||
// { id: 2, name: '2' } | ||
// ] | ||
``` | ||
- `treeCheck(data, checkIds, props)` tree node check | ||
get all associated node'id by check one node. | ||
arguments: | ||
| name | type | description | | ||
| ---------- | ------------------- | --------------------- | | ||
| `data` | (same) | (same) | | ||
| `checkIds` | `number[]/string[]` | will checked node ids | | ||
| `props` | (same) | (same) | | ||
```js | ||
import { treeCheck } from "operation-tree-node"; | ||
const treeData = [{ id: 1, name: "123", children: [{ id: 2, name: "2" }] }]; | ||
const resultIds = treeCheck(treeData, [2], { | ||
id: "id", | ||
children: "children", | ||
parent: "parent" | ||
}); | ||
console.log(resultIds); | ||
// [2, 1] | ||
``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21
256
32024
1
28
733
1
+ Addedcore-js@^3.x
+ Addedcore-js@3.40.0(transitive)