@dyrl/utils
Advanced tools
+25
-21
@@ -1,2 +0,2 @@ | ||
| import { defaults } from 'lodash-es'; | ||
| import { defaults, isNil } from 'lodash-es'; | ||
| export var toTreeData = function toTreeData(data, fieldNames, iteratee) { | ||
@@ -15,29 +15,33 @@ var _defaults = defaults(fieldNames, { | ||
| childrenKey = _defaults.children; | ||
| var treeData = []; | ||
| var dataMap = new Map(data.map(function (item) { | ||
| return [item[idKey], item]; | ||
| })); | ||
| var dataMap = new Map(); | ||
| var formatData = data.map(function (item) { | ||
| var id = item[idKey]; | ||
| var parentId = item[parentIdKey]; | ||
| var tempItem = { | ||
| id: id, | ||
| key: id, | ||
| parentId: parentId, | ||
| _original: item, | ||
| value: item[valueKey], | ||
| label: item[labelKey] | ||
| }; | ||
| dataMap.set(id, tempItem); | ||
| return tempItem; | ||
| }); | ||
| var loop = function loop(data) { | ||
| var treeData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
| data.forEach(function (item) { | ||
| var _iteratee; | ||
| var id = item[idKey]; | ||
| var parentId = item[parentIdKey]; | ||
| var parentNode = dataMap.get(parentId); | ||
| var iterateeItem = (_iteratee = iteratee === null || iteratee === void 0 ? void 0 : iteratee(item)) !== null && _iteratee !== void 0 ? _iteratee : { | ||
| id: id, | ||
| key: id, | ||
| parentId: parentId, | ||
| _original: item, | ||
| value: item[valueKey], | ||
| label: item[labelKey] | ||
| }; | ||
| if (parentNode) { | ||
| (parentNode[childrenKey] || (parentNode[childrenKey] = [])).push(iterateeItem); | ||
| } else { | ||
| if (isNil(item.parentId)) return; | ||
| var parentNode = dataMap.get(item.parentId); | ||
| var iterateeItem = (_iteratee = iteratee === null || iteratee === void 0 ? void 0 : iteratee(item)) !== null && _iteratee !== void 0 ? _iteratee : item; | ||
| if (!parentNode) { | ||
| treeData.push(iterateeItem); | ||
| return; | ||
| } | ||
| (parentNode[childrenKey] || (parentNode[childrenKey] = [])).push(iterateeItem); | ||
| }); | ||
| return treeData; | ||
| }; | ||
| loop(data); | ||
| return treeData; | ||
| return loop(formatData); | ||
| }; |
+1
-1
| { | ||
| "name": "@dyrl/utils", | ||
| "version": "1.0.32", | ||
| "version": "1.0.34", | ||
| "description": "A react library developed with dumi", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
60260
0.31%748
0.54%