Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

operation-tree-node

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

operation-tree-node - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

2

dist/index.js
/*!
* 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.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc