operation-tree-node
Advanced tools
Comparing version 1.0.8 to 1.0.9
/*! | ||
* operation-tree-node v1.0.8 | ||
* operation-tree-node v1.0.9 | ||
* (c) 2019-2021 yujinpan | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* operation-tree-node v1.0.8 | ||
* operation-tree-node v1.0.9 | ||
* (c) 2019-2021 yujinpan | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* operation-tree-node v1.0.8 | ||
* operation-tree-node v1.0.9 | ||
* (c) 2019-2021 yujinpan | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* operation-tree-node v1.0.8 | ||
* operation-tree-node v1.0.9 | ||
* (c) 2019-2021 yujinpan | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
@@ -18,2 +18,2 @@ import { TreeDataProps, TreeEachCallback } from './types'; | ||
*/ | ||
export default function treeFilter<T>(data: T[], callback: TreeEachCallback<boolean, T>, props?: TreeDataProps): T[]; | ||
export default function treeFilter<T extends Record<string, any>>(data: T[], callback: TreeEachCallback<boolean, T>, props?: TreeDataProps, isStrictly?: boolean): T[]; |
/*! | ||
* operation-tree-node v1.0.8 | ||
* operation-tree-node v1.0.9 | ||
* (c) 2019-2021 yujinpan | ||
@@ -29,6 +29,5 @@ * Released under the MIT License. | ||
function treeFilter(data, callback) { | ||
var props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { | ||
children: 'children' | ||
}; | ||
var propsChildren = props.children; | ||
var props = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var isStrictly = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
var propsChildren = props.children || 'children'; | ||
var children; | ||
@@ -38,21 +37,46 @@ return function recursive(data, parent) { | ||
var newItem, newItemChildren, hasChildren; | ||
data.forEach(function (node, index, arr) { | ||
hasChildren = false; | ||
newItem = copy(node); | ||
children = node[propsChildren]; | ||
if (checkValidArray(children)) { | ||
newItemChildren = recursive(children, newItem); | ||
if (isStrictly) { | ||
data.forEach(function (node, index, arr) { | ||
if (callback(node, index, arr, parent)) { | ||
newItem = copy(node); | ||
children = node[propsChildren]; | ||
if (hasChildren = checkValidArray(newItemChildren)) { | ||
newItem[propsChildren] = newItemChildren; | ||
} else { | ||
delete newItem[propsChildren]; | ||
if (checkValidArray(children)) { | ||
newItemChildren = recursive(children, newItem); | ||
if (checkValidArray(newItemChildren)) { | ||
// @ts-ignore | ||
newItem[propsChildren] = newItemChildren; | ||
} else { | ||
delete newItem[propsChildren]; | ||
} | ||
} | ||
result.push(newItem); | ||
} | ||
} | ||
}); | ||
} else { | ||
data.forEach(function (node, index, arr) { | ||
hasChildren = false; | ||
newItem = copy(node); | ||
children = node[propsChildren]; | ||
if (callback(node, index, arr, parent) || hasChildren) { | ||
result.push(newItem); | ||
} | ||
}); | ||
if (checkValidArray(children)) { | ||
newItemChildren = recursive(children, newItem); | ||
if (hasChildren = checkValidArray(newItemChildren)) { | ||
// @ts-ignore | ||
newItem[propsChildren] = newItemChildren; | ||
} else { | ||
delete newItem[propsChildren]; | ||
} | ||
} | ||
if (callback(node, index, arr, parent) || hasChildren) { | ||
result.push(newItem); | ||
} | ||
}); | ||
} | ||
return result; | ||
@@ -59,0 +83,0 @@ }(data); |
/*! | ||
* operation-tree-node v1.0.8 | ||
* operation-tree-node v1.0.9 | ||
* (c) 2019-2021 yujinpan | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* operation-tree-node v1.0.8 | ||
* operation-tree-node v1.0.9 | ||
* (c) 2019-2021 yujinpan | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* operation-tree-node v1.0.8 | ||
* operation-tree-node v1.0.9 | ||
* (c) 2019-2021 yujinpan | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* operation-tree-node v1.0.8 | ||
* operation-tree-node v1.0.9 | ||
* (c) 2019-2021 yujinpan | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* operation-tree-node v1.0.8 | ||
* operation-tree-node v1.0.9 | ||
* (c) 2019-2021 yujinpan | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* operation-tree-node v1.0.8 | ||
* operation-tree-node v1.0.9 | ||
* (c) 2019-2021 yujinpan | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* operation-tree-node v1.0.8 | ||
* operation-tree-node v1.0.9 | ||
* (c) 2019-2021 yujinpan | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
/*! | ||
* operation-tree-node v1.0.8 | ||
* operation-tree-node v1.0.9 | ||
* (c) 2019-2021 yujinpan | ||
@@ -4,0 +4,0 @@ * Released under the MIT License. |
{ | ||
"name": "operation-tree-node", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"author": "yujinpan", | ||
@@ -5,0 +5,0 @@ "module": "dist/index.js", |
@@ -94,3 +94,3 @@ Operation method collection for tree node(like operation array). | ||
- `treeFilter(data, callback, props)` tree node filter(like `Array.prototype.filter`) | ||
- `treeFilter(data, callback, props, isStrictly)` tree node filter(like `Array.prototype.filter`) | ||
@@ -97,0 +97,0 @@ get a new data instead of change source. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32787
752