tree-processor 0.8.1 → 0.9.0

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.
@@ -5,17 +5,17 @@ return function r(n){for(const o of n){i.push(e(o))
5
5
  const n=o[t.children]
6
6
  Array.isArray(n)&&n.length>0&&r(n)}}(r),i}function t(r,e,t=n){const i=[]
7
7
  return function r(n){n.forEach((n,o)=>{e(n,o)&&i.push(n)
8
- const f=n[t.children]
9
- Array.isArray(f)&&f.length>0&&r(f,o)})}(r),i}function i(r,e,t=n){for(const n of r){if(e(n))return n
8
+ const c=n[t.children]
9
+ Array.isArray(c)&&c.length>0&&r(c)})}(r),i}function i(r,e,t=n){for(const n of r){if(e(n))return n
10
10
  const r=n[t.children]
11
11
  if(Array.isArray(r)&&r.length>0){const n=i(r,e,t)
12
12
  if(n)return n}}return null}function o(r,e,t,i=n){return function r(n){for(const o of n){if(o[i.id]===e)return o[i.children]||(o[i.children]=[]),o[i.children].push(t),!0
13
13
  const n=o[i.children]
14
- if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(r)}function f(r,e,t,i=n){return function r(n){for(const o of n){if(o[i.id]===e)return o[i.children]||(o[i.children]=[]),o[i.children].unshift(t),!0
14
+ if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(r)}function c(r,e,t,i=n){return function r(n){for(const o of n){if(o[i.id]===e)return o[i.children]||(o[i.children]=[]),o[i.children].unshift(t),!0
15
15
  const n=o[i.children]
16
- if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(r)}function u(r,e,t=n){return function r(n){for(const i of n){if(i[t.id]===e){const r=i[t.children]
16
+ if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(r)}function f(r,e,t=n){return function r(n){for(const i of n){if(i[t.id]===e){const r=i[t.children]
17
17
  return!!(Array.isArray(r)&&r.length>0)&&(r.pop(),!0)}const n=i[t.children]
18
- if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(r)}function c(r,e,t=n){return function r(n){for(const i of n){if(i[t.id]===e){const r=i[t.children]
18
+ if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(r)}function u(r,e,t=n){return function r(n){for(const i of n){if(i[t.id]===e){const r=i[t.children]
19
19
  return!!(Array.isArray(r)&&r.length>0)&&(r.shift(),!0)}const n=i[t.children]
20
20
  if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(r)}function s(r,e,t=n){for(const n of r){if(e(n))return!0
21
21
  const r=n[t.children]
@@ -26,22 +26,22 @@ const n=t[i.children]
26
26
  if(Array.isArray(n)&&n.length>0){const e=r(n)
27
27
  if(e)return e}}return null}(r)
28
28
  if(!o)return null
29
- const f=o[i.children]
30
- if(!Array.isArray(f)||0===f.length)return null
31
- const u=t>=0?t:f.length+t
32
- return u>=0&&u<f.length?f[u]:null}function h(r,e,t=n){return function r(n,i=[]){for(let o=0;o<n.length;o++){const f=n[o],u=[...i,o]
33
- if(f[t.id]===e)return u
34
- const c=f[t.children]
35
- if(Array.isArray(c)&&c.length>0){const n=r(c,u)
29
+ const c=o[i.children]
30
+ if(!Array.isArray(c)||0===c.length)return null
31
+ const f=t>=0?t:c.length+t
32
+ return f>=0&&f<c.length?c[f]:null}function h(r,e,t=n){return function r(n,i=[]){for(let o=0;o<n.length;o++){const c=n[o],f=[...i,o]
33
+ if(c[t.id]===e)return f
34
+ const u=c[t.children]
35
+ if(Array.isArray(u)&&u.length>0){const n=r(u,f)
36
36
  if(n)return n}}return null}(r)}function d(r,e,t=n){if(!Array.isArray(e)||0===e.length)return null
37
37
  let i=r
38
38
  for(let r=0;r<e.length;r++){const n=e[r]
39
39
  if(!Array.isArray(i)||n<0||n>=i.length)return null
40
40
  const o=i[n]
41
41
  if(r===e.length-1)return o
42
- const f=o[t.children]
43
- if(!Array.isArray(f))return null
44
- i=f}return null}function y(r,e=n){const t={}
42
+ const c=o[t.children]
43
+ if(!Array.isArray(c))return null
44
+ i=c}return null}function y(r,e=n){const t={}
45
45
  return function r(n,i=1){for(const o of n){t[o[e.id]]=i
46
46
  const n=o[e.children]
47
47
  Array.isArray(n)&&n.length>0&&r(n,i+1)}}(r),t}function A(r,e,t=n){return function r(n,i=1){for(const o of n){if(o[t.id]===e)return i
@@ -49,51 +49,86 @@ const n=o[t.children]
49
49
  if(Array.isArray(n)&&n.length>0){const e=r(n,i+1)
50
50
  if(null!==e)return e}}return null}(r)}function T(r,e,t=n){const i=new Set
51
51
  return function r(n){const o=[]
52
- for(const f of n){const n=f[e]
52
+ for(const c of n){const n=c[e]
53
53
  if(null!=n){if(i.has(n))continue
54
- i.add(n)}const u={...f},c=f[t.children]
55
- Array.isArray(c)&&c.length>0&&(u[t.children]=r(c)),o.push(u)}return o}(r)}function g(r,e,t=n){return function r(n){for(let i=0;i<n.length;i++){const o=n[i]
54
+ i.add(n)}const f={...c},u=c[t.children]
55
+ Array.isArray(u)&&u.length>0&&(f[t.children]=r(u)),o.push(f)}return o}(r)}function g(r,e,t=n){return function r(n){for(let i=0;i<n.length;i++){const o=n[i]
56
56
  if(o[t.id]===e)return n.splice(i,1),!0
57
- const f=o[t.children]
58
- if(Array.isArray(f)&&f.length>0&&r(f))return!0}return!1}(r)}function p(r,e,t=n){!function r(n){for(const i of n){e(i)
57
+ const c=o[t.children]
58
+ if(Array.isArray(c)&&c.length>0&&r(c))return!0}return!1}(r)}function p(r,e,t=n){!function r(n){for(const i of n){e(i)
59
59
  const n=i[t.children]
60
- Array.isArray(n)&&n.length>0&&r(n)}}(r)}function D(r){return!Array.isArray(r)||0===r.length}function m(r,e=n){if(!x(r,e))return!0
60
+ Array.isArray(n)&&n.length>0&&r(n)}}(r)}function v(r){return!Array.isArray(r)||0===r.length}function b(r,e=n){if(!j(r,e))return!0
61
61
  const t=r[e.children]
62
- return void 0===t||(!Array.isArray(t)||0===t.length)}function N(r,e,t=n){const i=function r(n){for(const i of n){if(i[t.id]===e)return i
62
+ return void 0===t||!Array.isArray(t)||0===t.length}function m(r,e,t=n){const i=function r(n){for(const i of n){if(i[t.id]===e)return i
63
63
  const n=i[t.children]
64
64
  if(Array.isArray(n)&&n.length>0){const e=r(n)
65
65
  if(null!==e)return e}}return null}(r)
66
66
  if(!i)return[]
67
67
  const o=i[t.children]
68
- return Array.isArray(o)?o:[]}function S(r,e,t=n){const i=function r(n,i=null){for(const o of n){if(o[t.id]===e)return{node:o,parent:i}
68
+ return Array.isArray(o)?o:[]}function D(r,e,t=n){const i=function r(n,i=null){for(const o of n){if(o[t.id]===e)return{node:o,parent:i}
69
69
  const n=o[t.children]
70
70
  if(Array.isArray(n)&&n.length>0){const e=r(n,o)
71
71
  if(null!==e)return e}}return null}(r)
72
72
  if(!i)return[]
73
73
  if(null===i.parent)return r
74
74
  const o=i.parent[t.children]
75
- return Array.isArray(o)?o:[]}function v(r,e,t=n){return function r(n,i=null){for(const o of n){if(o[t.id]===e)return i
75
+ return Array.isArray(o)?o:[]}function N(r,e,t=n){return function r(n,i=null){for(const o of n){if(o[t.id]===e)return i
76
76
  const n=o[t.children]
77
77
  if(Array.isArray(n)&&n.length>0){const e=r(n,o)
78
- if(null!==e)return e}}return null}(r)}function b(r,e,t=n){for(const n of r){if(n[t.id]===e)return!0
78
+ if(null!==e)return e}}return null}(r)}function S(r,e,t=n){for(const n of r){if(n[t.id]===e)return!0
79
79
  const r=n[t.children]
80
- if(Array.isArray(r)&&r.length>0&&b(r,e,t))return!0}return!1}function x(r,e=n){if(!r||"object"!=typeof r||Array.isArray(r))return!1
80
+ if(Array.isArray(r)&&r.length>0&&S(r,e,t))return!0}return!1}function j(r,e=n){if(!r||"object"!=typeof r||Array.isArray(r))return!1
81
81
  const t=r[e.children]
82
82
  if(void 0!==t){if(null===t)return!1
83
83
  if(!Array.isArray(t))return!1
84
- for(const r of t)if(!x(r,e))return!1}return!0}function E(r,e=n){if(!Array.isArray(r))return!1
85
- for(const n of r)if(!x(n,e))return!1
86
- return!0}function C(r,e=n){if(!r||"object"!=typeof r||Array.isArray(r))return!1
84
+ for(const r of t)if(!j(r,e))return!1}return!0}function M(r,e=n){if(!Array.isArray(r))return!1
85
+ for(const n of r)if(!j(n,e))return!1
86
+ return!0}function E(r,e=n){if(!r||"object"!=typeof r||Array.isArray(r))return!1
87
87
  const t=r[e.children]
88
- return void 0===t||Array.isArray(t)}function j(r,e=n,t=new WeakSet){if(!r||"object"!=typeof r||Array.isArray(r))return!1
88
+ return void 0===t||Array.isArray(t)}function O(r,e=n,t=new WeakSet){if(!r||"object"!=typeof r||Array.isArray(r))return!1
89
89
  if(t.has(r))return!1
90
90
  t.add(r)
91
91
  const i=r[e.children]
92
92
  if(void 0!==i){if(null===i)return!1
93
93
  if(!Array.isArray(i))return!1
94
- for(const r of i)if(!j(r,e,t))return!1}return!0}function O(r,e,t=n){if(e<=0)return!1
95
- return function r(n,i){if(i>e)return!1
94
+ for(const r of i)if(!O(r,e,t))return!1}return!0}function k(r,e,t=n){return!(e<=0)&&function r(n,i){if(i>e)return!1
96
95
  for(const e of n){const n=e[t.children]
97
- if(Array.isArray(n)&&n.length>0&&!r(n,i+1))return!1}return!0}(r,1)}function M(r,e=n){const t=r[e.children]
98
- return void 0===t||!Array.isArray(t)||0===t.length}function P(r,e,t=n){return!!b(r,e,t)&&null===v(r,e,t)}const k={mapTree:e,filterTree:t,findTree:i,pushTree:o,unshiftTree:f,popTree:u,shiftTree:c,someTree:s,everyTree:l,atTree:a,indexOfTree:h,atIndexOfTree:d,getNodeDepthMap:y,getNodeDepth:A,dedupTree:T,removeTree:g,forEachTree:p,isEmptyTreeData:D,isEmptySingleTreeData:m,getParentTree:v,getChildrenTree:N,getSiblingsTree:S,includesTree:b,isSingleTreeData:x,isTreeData:E,isValidTreeNode:C,isTreeNodeWithCircularCheck:j,isSafeTreeDepth:O,isLeafNode:M,isRootNode:P}
99
- r.atIndexOfTree=d,r.atTree=a,r.dedupTree=T,r.default=k,r.everyTree=l,r.filterTree=t,r.findTree=i,r.forEachTree=p,r.getChildrenTree=N,r.getNodeDepth=A,r.getNodeDepthMap=y,r.getParentTree=v,r.getSiblingsTree=S,r.includesTree=b,r.indexOfTree=h,r.isEmptySingleTreeData=m,r.isEmptyTreeData=D,r.isLeafNode=M,r.isRootNode=P,r.isSafeTreeDepth=O,r.isSingleTreeData=x,r.isTreeData=E,r.isTreeNodeWithCircularCheck=j,r.isValidTreeNode=C,r.mapTree=e,r.popTree=u,r.pushTree=o,r.removeTree=g,r.shiftTree=c,r.someTree=s,r.unshiftTree=f,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})
96
+ if(Array.isArray(n)&&n.length>0&&!r(n,i+1))return!1}return!0}(r,1)}function x(r,e=n){const t=r[e.children]
97
+ return void 0===t||!Array.isArray(t)||0===t.length}function C(r,e,t=n){return!!S(r,e,t)&&null===N(r,e,t)}function I(r,e=n){const t=[]
98
+ return function r(n){for(const i of n){const{[e.children]:n,...o}=i
99
+ t.push(o)
100
+ const c=i[e.children]
101
+ Array.isArray(c)&&c.length>0&&r(c)}}(r),t}function P(r,e={}){const{rootParentId:t=null,parentIdField:i="parentId",fieldNames:o=n}=e
102
+ if(Array.isArray(r)){if(0===r.length)return[]
103
+ const n=new Map
104
+ for(const e of r){const r=e[o.id]
105
+ if(null==r)continue
106
+ const t={...e,[o.children]:[]}
107
+ n.set(r,t)}const e=[]
108
+ for(const c of r){const r=c[o.id],f=c[i]
109
+ if(null==r)continue
110
+ const u=n.get(r)
111
+ if(u)if(f===t||null==f)e.push(u)
112
+ else{const r=n.get(f)
113
+ if(r){const n=r[o.children]
114
+ Array.isArray(n)?n.push(u):r[o.children]=[u]}else e.push(u)}}return e}if(r instanceof Map){if(0===r.size)return[]
115
+ const n=[]
116
+ return r.forEach((r,e)=>{n.push({...r,[o.id]:e})}),P(n,e)}if(r&&"object"==typeof r&&!Array.isArray(r)&&!(r instanceof Map)){const n=r[o.children]
117
+ if(Array.isArray(n))return[r]
118
+ const t=Object.keys(r)
119
+ if(t.length>0){let n=!0
120
+ for(const e of t){const t=r[e]
121
+ if(!t||"object"!=typeof t||Array.isArray(t)){n=!1
122
+ break}}if(n){const n=[]
123
+ for(const e of t){const t=r[e]
124
+ n.push({...t,[o.id]:e})}if(n.length>0)return P(n,e)}}return[{...r,[o.children]:[]}]}return[]}function w(r,e=n){const t=new Map
125
+ return function r(n){for(const i of n){const n=i[e.id]
126
+ if(null!=n){const{[e.children]:r,...o}=i
127
+ t.set(n,o)}const o=i[e.children]
128
+ Array.isArray(o)&&o.length>0&&r(o)}}(r),t}function L(r,e=n){const t=[]
129
+ return Array.isArray(r)&&0!==r.length?(function r(n,i=0){t[i]||(t[i]=[])
130
+ for(const o of n){const{[e.children]:n,...c}=o
131
+ t[i].push(c)
132
+ const f=o[e.children]
133
+ Array.isArray(f)&&f.length>0&&r(f,i+1)}}(r),t):[]}function W(r){return Array.isArray(r)&&0!==r.length&&1===r.length?r[0]:null}const B={mapTree:e,filterTree:t,findTree:i,pushTree:o,unshiftTree:c,popTree:f,shiftTree:u,someTree:s,everyTree:l,atTree:a,indexOfTree:h,atIndexOfTree:d,getNodeDepthMap:y,getNodeDepth:A,dedupTree:T,removeTree:g,forEachTree:p,isEmptyTreeData:v,isEmptySingleTreeData:b,getParentTree:N,getChildrenTree:m,getSiblingsTree:D,includesTree:S,isSingleTreeData:j,isTreeData:M,isValidTreeNode:E,isTreeNodeWithCircularCheck:O,isSafeTreeDepth:k,isLeafNode:x,isRootNode:C,convertToArrayTree:I,convertBackTree:P,convertToMapTree:w,convertToLevelArrayTree:L,convertToObjectTree:W}
134
+ r.atIndexOfTree=d,r.atTree=a,r.convertBackTree=P,r.convertToArrayTree=I,r.convertToLevelArrayTree=L,r.convertToMapTree=w,r.convertToObjectTree=W,r.dedupTree=T,r.default=B,r.everyTree=l,r.filterTree=t,r.findTree=i,r.forEachTree=p,r.getChildrenTree=m,r.getNodeDepth=A,r.getNodeDepthMap=y,r.getParentTree=N,r.getSiblingsTree=D,r.includesTree=S,r.indexOfTree=h,r.isEmptySingleTreeData=b,r.isEmptyTreeData=v,r.isLeafNode=x,r.isRootNode=C,r.isSafeTreeDepth=k,r.isSingleTreeData=j,r.isTreeData=M,r.isTreeNodeWithCircularCheck=O,r.isValidTreeNode=E,r.mapTree=e,r.popTree=f,r.pushTree=o,r.removeTree=g,r.shiftTree=u,r.someTree=s,r.unshiftTree=c,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})})
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-processor",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "A lightweight TypeScript library for processing tree-structured data with comprehensive methods (map, filter, find, push, pop, remove, getParent, includes, etc.), supporting tree-shaking and custom field names",
5
5
  "main": "dist/tree-processor.cjs.js",
6
6
  "module": "dist/tree-processor.esm.js",
@@ -20,13 +20,18 @@
20
20
  "README.md"
21
21
  ],
22
22
  "scripts": {
23
- "build": "rollup -c",
24
- "test": "vitest",
23
+ "build": "rimraf dist && rollup -c",
24
+ "test": "npm run build && vitest run src/index-all-dist.test.ts",
25
+ "test:src": "vitest run src/index.test.ts",
26
+ "test:dist": "npm run build && vitest run src/index-dist-only.test.ts",
25
27
  "test:coverage": "vitest --coverage",
28
+ "update:badge": "node scripts/update-coverage-badge.js",
29
+ "update:downloads": "node scripts/update-downloads-badge.js",
26
30
  "size:dist": "node scripts/check-size.js",
27
31
  "size:src": "node scripts/check-src-size.js",
28
32
  "size:all": "npm run size:src && npm run size:dist",
29
- "prepublishOnly": "npm run build"
33
+ "prepublishOnly": "npm run build",
34
+ "ci": "npm test -- --run && npm run test:coverage && npm run update:badge && npm run update:downloads"
30
35
  },
31
36
  "keywords": [
32
37
  "tree",
@@ -46,12 +51,6 @@
46
51
  "deduplicate",
47
52
  "menu",
48
53
  "navigation",
49
- "file-tree",
50
- "directory",
51
- "category",
52
- "comment",
53
- "permission",
54
- "tree-select",
55
54
  "tree-processor"
56
55
  ],
57
56
  "author": "",
@@ -67,7 +66,9 @@
67
66
  "@rollup/plugin-typescript": "^12.1.0",
68
67
  "@types/node": "^22.10.2",
69
68
  "@vitest/coverage-v8": "^4.0.18",
69
+ "rimraf": "^6.1.2",
70
70
  "rollup": "^4.24.0",
71
+ "rollup-plugin-node-externals": "^8.1.2",
71
72
  "rollup-plugin-visualizer": "^6.0.5",
72
73
  "terser": "^5.36.0",
73
74
  "tslib": "^2.8.1",