Socket
Socket
Sign inDemoInstall

simple-tree-utils

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.0 to 0.0.1

3

dist/browser-bundle.js

@@ -57,2 +57,5 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.treeUtils = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){

static addNode(tree, parentId, child) {
if (parentId == null) {
tree.push(child);
}
const index = tree.findIndex(item => item.id == parentId);

@@ -59,0 +62,0 @@ if (index != -1) {

2

dist/browser-bundle.min.js

@@ -1,1 +0,1 @@

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.treeUtils=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r}()({1:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.TreeUtils=void 0;var main_1=require("./main");Object.defineProperty(exports,"TreeUtils",{enumerable:true,get:function(){return main_1.TreeUtils}})},{"./main":2}],2:[function(require,module,exports){"use strict";var __rest=this&&this.__rest||function(s,e){var t={};for(var p in s)if(Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0)t[p]=s[p];if(s!=null&&typeof Object.getOwnPropertySymbols==="function")for(var i=0,p=Object.getOwnPropertySymbols(s);i<p.length;i++){if(e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i]))t[p[i]]=s[p[i]]}return t};Object.defineProperty(exports,"__esModule",{value:true});exports.TreeUtils=void 0;class TreeUtils{static list2Tree(list,parentId=null){return list.filter(item=>item.parentId===parentId).map(item=>Object.assign(Object.assign({},item),{children:this.list2Tree(list,item.id)}))}static tree2List(tree,parentId=null){return tree.reduce((acc,curr)=>{const{children}=curr,rest=__rest(curr,["children"]);return[...acc,Object.assign(Object.assign({},rest),{parentId:parentId}),...children.length?this.tree2List(children,rest.id):[]]},[])}static findTreeNodeById(tree,id){const node=tree.find(item=>item.id===id);if(node){return node}return tree.reduce((acc,curr)=>acc||this.findTreeNodeById(curr.children||[],id),null)}static deleteNode(tree,id){const index=tree.findIndex(item=>item.id==id);if(index!=-1){tree.splice(index,1);return}tree.forEach(item=>{item.children&&this.deleteNode(item.children,id)})}static addNode(tree,parentId,child){const index=tree.findIndex(item=>item.id==parentId);if(index!=-1){tree[index].children=tree[index].children?[...tree[index].children,child]:[child];return}tree.forEach(item=>{item.children&&this.addNode(item.children,parentId,child)})}static editNode(tree,id,data){const index=tree.findIndex(item=>item.id==id);if(index!=-1){tree[index]=Object.assign(Object.assign({id:tree[index].id},data),data.children?{children:[]}:{});return}tree.forEach(item=>{item.children&&this.editNode(item.children,id,data)})}}exports.TreeUtils=TreeUtils},{}]},{},[1])(1)});
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.treeUtils=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r}()({1:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.TreeUtils=void 0;var main_1=require("./main");Object.defineProperty(exports,"TreeUtils",{enumerable:true,get:function(){return main_1.TreeUtils}})},{"./main":2}],2:[function(require,module,exports){"use strict";var __rest=this&&this.__rest||function(s,e){var t={};for(var p in s)if(Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0)t[p]=s[p];if(s!=null&&typeof Object.getOwnPropertySymbols==="function")for(var i=0,p=Object.getOwnPropertySymbols(s);i<p.length;i++){if(e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i]))t[p[i]]=s[p[i]]}return t};Object.defineProperty(exports,"__esModule",{value:true});exports.TreeUtils=void 0;class TreeUtils{static list2Tree(list,parentId=null){return list.filter(item=>item.parentId===parentId).map(item=>Object.assign(Object.assign({},item),{children:this.list2Tree(list,item.id)}))}static tree2List(tree,parentId=null){return tree.reduce((acc,curr)=>{const{children}=curr,rest=__rest(curr,["children"]);return[...acc,Object.assign(Object.assign({},rest),{parentId:parentId}),...children.length?this.tree2List(children,rest.id):[]]},[])}static findTreeNodeById(tree,id){const node=tree.find(item=>item.id===id);if(node){return node}return tree.reduce((acc,curr)=>acc||this.findTreeNodeById(curr.children||[],id),null)}static deleteNode(tree,id){const index=tree.findIndex(item=>item.id==id);if(index!=-1){tree.splice(index,1);return}tree.forEach(item=>{item.children&&this.deleteNode(item.children,id)})}static addNode(tree,parentId,child){if(parentId==null){tree.push(child)}const index=tree.findIndex(item=>item.id==parentId);if(index!=-1){tree[index].children=tree[index].children?[...tree[index].children,child]:[child];return}tree.forEach(item=>{item.children&&this.addNode(item.children,parentId,child)})}static editNode(tree,id,data){const index=tree.findIndex(item=>item.id==id);if(index!=-1){tree[index]=Object.assign(Object.assign({id:tree[index].id},data),data.children?{children:[]}:{});return}tree.forEach(item=>{item.children&&this.editNode(item.children,id,data)})}}exports.TreeUtils=TreeUtils},{}]},{},[1])(1)});

@@ -49,2 +49,5 @@ "use strict";

static addNode(tree, parentId, child) {
if (parentId == null) {
tree.push(child);
}
const index = tree.findIndex(item => item.id == parentId);

@@ -51,0 +54,0 @@ if (index != -1) {

{
"name": "simple-tree-utils",
"version": "0.0.0",
"version": "0.0.1",
"description": "Tree utils library.",

@@ -5,0 +5,0 @@ "keywords": [],

@@ -45,2 +45,5 @@ export class TreeUtils {

static addNode(tree: any[], parentId: any, child: any): void {
if (parentId == null) {
tree.push(child);
}
const index = tree.findIndex(item => item.id == parentId);

@@ -47,0 +50,0 @@ if (index != -1) {

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc