sh-tools 2.1.6 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packages/utils/array.js +20 -0
package/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const removeTree = (treeData, func, options) => {
|
|
2
|
+
treeData.forEach((node, nodeIndex) => {
|
|
3
|
+
if (func && func(node, nodeIndex)) {
|
|
4
|
+
treeData.splice(nodeIndex, 1)
|
|
5
|
+
}
|
|
6
|
+
// 对树节点的后代进行递归
|
|
7
|
+
const child = node[options?.children || 'children']
|
|
8
|
+
if (child && child.length > 0) {
|
|
9
|
+
removeTree(child, func, options)
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
removeTree,
|
|
16
|
+
swapArray(arr, toIndex, fromIndex) {
|
|
17
|
+
arr[toIndex] = arr.splice(fromIndex, 1, arr[toIndex])[0]
|
|
18
|
+
return arr
|
|
19
|
+
}
|
|
20
|
+
}
|