{"_id":"@3mcode/tree-helper","_rev":"5-d938959d9489457340ba168483907e16","time":{"created":"2022-01-25T07:59:15.404Z","0.1.0":"2022-01-25T07:48:38.994Z","modified":"2022-04-04T10:45:11.282Z","0.1.1":"2022-01-25T07:59:15.615Z","0.1.2":"2022-01-29T09:48:55.028Z"},"name":"@3mcode/tree-helper","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.1":{"name":"@3mcode/tree-helper","version":"0.1.1","description":"some useful tree functions","main":"dist/index.js","scripts":{"build":"npm-run-all build:*","build:npm":"rollup -c -f umd && tsc --emitDeclarationOnly","build:browser":"rollup -c -f iife"},"repository":{"type":"git","url":"git+https://github.com/flyaway98/treehelper.git"},"keywords":[],"author":"","license":"ISC","bugs":{"url":"https://github.com/flyaway98/treehelper/issues"},"homepage":"https://github.com/flyaway98/treehelper#readme","devDependencies":{"@babel/cli":"^7.16.8","@babel/core":"^7.16.10","@babel/plugin-transform-modules-umd":"^7.16.7","@babel/plugin-transform-runtime":"^7.16.10","@babel/preset-env":"^7.16.10","@babel/preset-typescript":"^7.16.7","@babel/runtime-corejs3":"^7.16.8","npm-run-all":"^4.1.5","rollup":"^2.64.0","rollup-plugin-babel":"^4.4.0","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-node-resolve":"^5.2.0","rollup-plugin-terser":"^7.0.2"},"gitHead":"3c43dad325e21070697c611b5c2777e5cb68ebd8","_id":"@3mcode/tree-helper@0.1.1","_nodeVersion":"12.18.4","_npmVersion":"7.6.3","dist":{"integrity":"sha512-DSbQX5gHXGv4Cn3+9S4WpyfBcZv9ADKyuhGtdMTvgHUC8XRh8SZbOdL2Pu31SOjYr0dUkpQ3/lFjR6OWyC3K2w==","shasum":"8966b3a99531a50020f01393fe6c5eaeb1ec0552","tarball":"https://registry.npmjs.org/@3mcode/tree-helper/-/tree-helper-0.1.1.tgz","fileCount":5,"unpackedSize":18815,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh763TCRA9TVsSAnZWagAAGs8P/A/BxXOy/5ACoyIGohqR\nx2G2acGmtFdgXnZHS7Q0S3a+GbYcZHDbdW+Cet+nguUP+i0F07ny6/gf2VVp\nct6GXRdWdK6f+zoO6FUF7Kgqm/pQigo3rhO1+0ohEeZIL7pVU+ENcr8pcQxr\nPuZre7sxLX43lexrQIW7B3FFC8Zl62njxzGNrvM6ojuWiQwlKfZt0rtLR0PG\nMj4j3HhwA1M0LtT5hNdo7n3eIkqxZf5+e+25cNhcV8ehJYqCgNO2t/N0LDGl\nYr0SZHgwns8HOsoCX7DBu3+iGhncB4tD4Ac29kU/HBcvYMeKOpGXuQmhds8i\nw/BdwHFocvR3U/PJDjhJkPbplTakQ+i6HPY/iA+2dhp7o9zDk52uVh0fTOlN\nhhMJcrdtyY0Oum+OArOqnlVdTVa9f3a7/wZ4qVUs56i0WlEWRvPvX29lJYEn\nUSGz6GqYaLpg5iGiuaeR14lmAkd3MWyjURwWsnhXhPe0sFJCCZX1SPgxPbdy\ndS9J52NgneW6trs76S+ErSICqhfrpnuLAKwIAg415VT8La8InkgcZKFebDWc\n5HecCHuf7gy4bo/PrRgsdC60C74HuqBuw3ynSXfj1cA7g52Jxyl3JMvpQ5N3\nXM6OVN7hpWuYCJISVzdzM32mlzI+RMmMkePuf3AduXKo1zx8ZruSC3wqft7g\nuAwd\r\n=tMDY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDlTiLhnFVUHidM233vBimv4AfL/KW8NVHdbeqIRw68lQIgJ4vrWnWVKxk2Pu9oPKXH7wF4NnmvmgLhEOnR42EFEt8="}]},"_npmUser":{"name":"3mcode","email":"hacker1985@qq.com"},"directories":{},"maintainers":[{"name":"3mcode","email":"hacker1985@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/tree-helper_0.1.1_1643097555457_0.8266748141040934"},"_hasShrinkwrap":false},"0.1.2":{"name":"@3mcode/tree-helper","version":"0.1.2","description":"some useful tree functions","main":"dist/index.js","scripts":{"build":"npm-run-all build:*","build:npm":"rollup -c -f umd && tsc --emitDeclarationOnly","build:browser":"rollup -c -f iife","test":"jest"},"repository":{"type":"git","url":"git+https://github.com/flyaway98/treehelper.git"},"keywords":[],"author":"","license":"ISC","bugs":{"url":"https://github.com/flyaway98/treehelper/issues"},"homepage":"https://github.com/flyaway98/treehelper#readme","devDependencies":{"@babel/cli":"^7.16.8","@babel/core":"^7.16.10","@babel/plugin-transform-modules-umd":"^7.16.7","@babel/plugin-transform-runtime":"^7.16.10","@babel/preset-env":"^7.16.10","@babel/preset-typescript":"^7.16.7","@babel/runtime-corejs3":"^7.16.8","@types/jest":"^27.4.0","jest":"^27.4.7","npm-run-all":"^4.1.5","rollup":"^2.64.0","rollup-plugin-babel":"^4.4.0","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-node-resolve":"^5.2.0","rollup-plugin-terser":"^7.0.2","ts-jest":"^27.1.3","typescript":"^4.5.5"},"gitHead":"1e2ef2b08c0d983b6d7d0eda61e8ec0bd26e32da","_id":"@3mcode/tree-helper@0.1.2","_nodeVersion":"12.18.4","_npmVersion":"7.6.3","dist":{"integrity":"sha512-8u3AR5Hs2wFUf9JBNrpFFTwNh54MWW3BsIMl0OPjMIZgozCE788N3zJfc/qoJJTXTPf+eF2KeMtpaWW663HVVg==","shasum":"afee8b386840f19f556523e7d9f59fe7d0d1b03b","tarball":"https://registry.npmjs.org/@3mcode/tree-helper/-/tree-helper-0.1.2.tgz","fileCount":6,"unpackedSize":20552,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh9Q2HCRA9TVsSAnZWagAA0eIP/RbhIZknanOoLZsQxK/F\nMIkw3775kYFte/yyktKbFC+g6LgF2jZY6bMLi/ZwpclgXZqg9xebT4EYomi5\ny87BBGIp5f1zZF0JWV4kTiKJ9ewnHpCf78tHbOZclLFyVVScKgVK8MTd35kq\n2b2PMd5GH95DK5HR1332uel433GuvJPMLsgb9TfCA6BeFxyc53M/CO+BM9zo\nsGrKfoUh0E64/5rvyL9julK5uiQxt731+bqlKahh4WzW3bgirGxH6PHkwMwT\nIpUfCXXzZcjUWqn6nYpNbJpB096M0hoCNIg/YfYy+nnY2SPDMJ+dff/biU90\nUfUutFZY+IYhOz+QejensQiYGq0qZH8Q/kNu4q2iyIHddq9878VC6ic8fLnz\nmkJ+xrgy0foNd9pkMHrq4AsCFnaH7zxaJGSkZ6DcOwCMYGflR8h2NpEZ8pHq\nT1jjvgEVKyHK7AFPcVY0zANCUYnYFQvaYoHnyhOClqyWh8kUolbwF0uZm/b1\nNuXarKndmj2f4yKpnAP++ZdoMiFfSnKuA3oPHmTKyRVgutvbkTPioRuvGrJ0\nZ96Ne5P3HJxGUPppC72i+QmhwGh7qsh5+KUKc/7Ugx0L/EswaR5i0pkMQ58a\nYJWjQJ5Cw8nmqFjUif7UbV2bNWgcTo8niZZULQ8aek4bMBM5UP6Lbk7nNDeJ\nU30t\r\n=TLWE\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCYhWbQjDEwLoeCBRms4qtMY3RF99Yn6IjuevZda4skOAIhAJsjVXl9zFEpcj0meRTwdc+PXK2LKI9aLv3DMq4G4suM"}]},"_npmUser":{"name":"3mcode","email":"hacker1985@qq.com"},"directories":{},"maintainers":[{"name":"3mcode","email":"hacker1985@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/tree-helper_0.1.2_1643449734875_0.8176020171118126"},"_hasShrinkwrap":false}},"maintainers":[{"name":"3mcode","email":"hacker1985@qq.com"}],"description":"some useful tree functions","homepage":"https://github.com/flyaway98/treehelper#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/flyaway98/treehelper.git"},"bugs":{"url":"https://github.com/flyaway98/treehelper/issues"},"license":"ISC","readme":"# tree-util\n\nsome useful tree functions\n\n## 1. data structure\n\nEach tree node must have three fields: id,name and children。eg:\n\n```javascript\n[\n  {\n    id: '1',\n    name: 'menuA',\n    children: [\n      { id: '21', name: 'menuA-1', menuCode: '21', children: [] },\n      { id: '22', name: 'menuA-2', menuCode: '22', children: [] },\n    ]\n  },\n  {\n    id: '2',\n    name: 'menuB',\n    children: []\n  }\n]\n\n```\n## 2.install\n\nmethod1:\n\n```javascript\nnpm i @3mcode/tree-helper -S\n\n```\n\nmethod2:\n\n```javascript\n<script src='dist/index-browser.js'></script>\n<script>\n treeHelper.methodXXX(); \n</script>\n\n```\n\nNote: if you want to use it in IE browser, the version should be > = 9\n\n## 3. methods\n\n\n\n### function flattenTree(items);\n\n```\n@description: flatten the nested tree into a normal array\n@param:\n[{id:'1',name:'1',children:[{id:'1-1',name:'1-1',children:[]}]}]\n@returns:\n[{id:'1',name:'1',parentId:null,depth:0,index:0,visitPath:'1,'},{id:'1-1',name:'1-1',parentId:'1',depth:1,index:0,visitPath:'1,1-1,'}]\n\n```\n\n### function buildTree(flattenedItems);\n```\n@description: convert flattened array to nested tree array\n@param:[{id:'1',name:'1',parentId:null,depth:0,index:0,visitPath:'1,'},{id:'1-1',name:'1-1',parentId:'1',depth:1,index:0,visitPath:'1,1-1,'}]\n@returns [{id:'1',name:'1',children:[{id:'1-1',name:'1-1',children:[]}]}]\n\n```\n\n### function visitTree(items, action);\n```\n@description: traversing the tree node\n@param: \nitems: tree nodes\naction: This function is called when traversing the tree node, and the tree node can be operated in the function\n\n```\n\n### function findItem(items, itemId);\n```\n@description: shallow search\n@params:\n  items:tree nodes,\n  itemId:node id to search\n@returns: treeNode or undefined\n\n```\n\n### function findItemDeep(items, itemId);\n```\n@description: deep search\n@params:\n  items:tree nodes,\n  itemId:node id to search\n@returns: tree node or undefined\n```\n\n### function removeItem(items, id);\n\n```\n@description: remove tree node\n@params:\n  items:tree nodes,\n  id:node id to remove\n@returns: return newtree nodes which not contains param id\n```\n\n### function setProperty(items, id, propertyName, setter);\n```\n@description: set tree node\n@params:\n  items:tree nodes,\n  id:node id to search,\n  propertyName: property name\n  setter: (treeNode) => newValue\n@returns: return newtree nodes, and not change  original tree nodes\n```\n### function getChildCount(items, id);\n\n```\n@description: count the number of all descendant nodes\n@params:\n  items:tree nodes,\n  id:node id to search,\n@returns: number of all descendant nodes\n```\n\n","readmeFilename":"README.md"}