tree-processor 0.1.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.
- package/LICENSE +21 -0
- package/README.md +249 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/stats.html +4949 -0
- package/dist/tree-processor.cjs.js +1 -0
- package/dist/tree-processor.esm.js +1 -0
- package/dist/tree-processor.umd.js +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const r={children:"children",id:"id"};function n(n,e,t=r){const i=[];return function r(n){for(const o of n){i.push(e(o));const n=o[t.children];Array.isArray(n)&&n.length>0&&r(n)}}(n),i}function e(n,e,t=r){const i=[];return function r(n,o=0){n.forEach((n,o)=>{e(n,o)&&i.push(n);const c=n[t.children];Array.isArray(c)&&c.length>0&&r(c,o)})}(n),i}function t(n,e,i=r){for(const r of n){if(e(r))return r;const n=r[i.children];if(Array.isArray(n)&&n.length>0){const r=t(n,e,i);if(r)return r}}return null}function i(n,e,t,i=r){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;const n=o[i.children];if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(n)}function o(n,e,t,i=r){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;const n=o[i.children];if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(n)}function c(n,e,t=r){return function r(n){for(const i of n){if(i[t.id]===e){const r=i[t.children];return!!(Array.isArray(r)&&r.length>0)&&(r.pop(),!0)}const n=i[t.children];if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(n)}function s(n,e,t=r){return function r(n){for(const i of n){if(i[t.id]===e){const r=i[t.children];return!!(Array.isArray(r)&&r.length>0)&&(r.shift(),!0)}const n=i[t.children];if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(n)}function u(n,e,t=r){for(const r of n){if(e(r))return!0;const n=r[t.children];if(Array.isArray(n)&&n.length>0&&u(n,e,t))return!0}return!1}function f(n,e,t=r){for(const r of n){if(!e(r))return!1;const n=r[t.children];if(Array.isArray(n)&&n.length>0&&!f(n,e,t))return!1}return!0}function l(n,e,t,i=r){const o=function r(n){for(const t of n){if(t[i.id]===e)return t;const n=t[i.children];if(Array.isArray(n)&&n.length>0){const e=r(n);if(e)return e}}return null}(n);if(!o)return null;const c=o[i.children];if(!Array.isArray(c)||0===c.length)return null;const s=t>=0?t:c.length+t;return s>=0&&s<c.length?c[s]:null}function h(n,e,t=r){return function r(n,i=[]){for(let o=0;o<n.length;o++){const c=n[o],s=[...i,o];if(c[t.id]===e)return s;const u=c[t.children];if(Array.isArray(u)&&u.length>0){const n=r(u,s);if(n)return n}}return null}(n)}function d(n,e,t=r){if(!Array.isArray(e)||0===e.length)return null;let i=n;for(let r=0;r<e.length;r++){const n=e[r];if(!Array.isArray(i)||n<0||n>=i.length)return null;const o=i[n];if(r===e.length-1)return o;const c=o[t.children];if(!Array.isArray(c))return null;i=c}return null}function a(n,e=r){const t={};return function r(n,i=1){for(const o of n){t[o[e.id]]=i;const n=o[e.children];Array.isArray(n)&&n.length>0&&r(n,i+1)}}(n),t}function y(n,e,t=r){const i=new Set;return function r(n){const o=[];for(const c of n){const n=c[e];if(null!=n){if(i.has(n))continue;i.add(n)}const s={...c},u=c[t.children];Array.isArray(u)&&u.length>0&&(s[t.children]=r(u)),o.push(s)}return o}(n)}const A={mapTree:n,filterTree:e,findTree:t,pushTree:i,unshiftTree:o,popTree:c,shiftTree:s,someTree:u,everyTree:f,atTree:l,indexOfTree:h,atIndexOfTree:d,nodeDepthMap:a,dedupTree:y};exports.atIndexOfTree=d,exports.atTree=l,exports.dedupTree=y,exports.default=A,exports.everyTree=f,exports.filterTree=e,exports.findTree=t,exports.indexOfTree=h,exports.mapTree=n,exports.nodeDepthMap=a,exports.popTree=c,exports.pushTree=i,exports.shiftTree=s,exports.someTree=u,exports.unshiftTree=o;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r={children:"children",id:"id"};function n(n,t,e=r){const i=[];return function r(n){for(const o of n){i.push(t(o));const n=o[e.children];Array.isArray(n)&&n.length>0&&r(n)}}(n),i}function t(n,t,e=r){const i=[];return function r(n,o=0){n.forEach((n,o)=>{t(n,o)&&i.push(n);const c=n[e.children];Array.isArray(c)&&c.length>0&&r(c,o)})}(n),i}function e(n,t,i=r){for(const r of n){if(t(r))return r;const n=r[i.children];if(Array.isArray(n)&&n.length>0){const r=e(n,t,i);if(r)return r}}return null}function i(n,t,e,i=r){return function r(n){for(const o of n){if(o[i.id]===t)return o[i.children]||(o[i.children]=[]),o[i.children].push(e),!0;const n=o[i.children];if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(n)}function o(n,t,e,i=r){return function r(n){for(const o of n){if(o[i.id]===t)return o[i.children]||(o[i.children]=[]),o[i.children].unshift(e),!0;const n=o[i.children];if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(n)}function c(n,t,e=r){return function r(n){for(const i of n){if(i[e.id]===t){const r=i[e.children];return!!(Array.isArray(r)&&r.length>0)&&(r.pop(),!0)}const n=i[e.children];if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(n)}function u(n,t,e=r){return function r(n){for(const i of n){if(i[e.id]===t){const r=i[e.children];return!!(Array.isArray(r)&&r.length>0)&&(r.shift(),!0)}const n=i[e.children];if(Array.isArray(n)&&n.length>0&&r(n))return!0}return!1}(n)}function f(n,t,e=r){for(const r of n){if(t(r))return!0;const n=r[e.children];if(Array.isArray(n)&&n.length>0&&f(n,t,e))return!0}return!1}function l(n,t,e=r){for(const r of n){if(!t(r))return!1;const n=r[e.children];if(Array.isArray(n)&&n.length>0&&!l(n,t,e))return!1}return!0}function s(n,t,e,i=r){const o=function r(n){for(const e of n){if(e[i.id]===t)return e;const n=e[i.children];if(Array.isArray(n)&&n.length>0){const t=r(n);if(t)return t}}return null}(n);if(!o)return null;const c=o[i.children];if(!Array.isArray(c)||0===c.length)return null;const u=e>=0?e:c.length+e;return u>=0&&u<c.length?c[u]:null}function h(n,t,e=r){return function r(n,i=[]){for(let o=0;o<n.length;o++){const c=n[o],u=[...i,o];if(c[e.id]===t)return u;const f=c[e.children];if(Array.isArray(f)&&f.length>0){const n=r(f,u);if(n)return n}}return null}(n)}function a(n,t,e=r){if(!Array.isArray(t)||0===t.length)return null;let i=n;for(let r=0;r<t.length;r++){const n=t[r];if(!Array.isArray(i)||n<0||n>=i.length)return null;const o=i[n];if(r===t.length-1)return o;const c=o[e.children];if(!Array.isArray(c))return null;i=c}return null}function d(n,t=r){const e={};return function r(n,i=1){for(const o of n){e[o[t.id]]=i;const n=o[t.children];Array.isArray(n)&&n.length>0&&r(n,i+1)}}(n),e}function y(n,t,e=r){const i=new Set;return function r(n){const o=[];for(const c of n){const n=c[t];if(null!=n){if(i.has(n))continue;i.add(n)}const u={...c},f=c[e.children];Array.isArray(f)&&f.length>0&&(u[e.children]=r(f)),o.push(u)}return o}(n)}const A={mapTree:n,filterTree:t,findTree:e,pushTree:i,unshiftTree:o,popTree:c,shiftTree:u,someTree:f,everyTree:l,atTree:s,indexOfTree:h,atIndexOfTree:a,nodeDepthMap:d,dedupTree:y};export{a as atIndexOfTree,s as atTree,y as dedupTree,A as default,l as everyTree,t as filterTree,e as findTree,h as indexOfTree,n as mapTree,d as nodeDepthMap,c as popTree,i as pushTree,u as shiftTree,f as someTree,o as unshiftTree};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((r="undefined"!=typeof globalThis?globalThis:r||self).TreeProcessor={})}(this,function(r){"use strict";const n={children:"children",id:"id"};function e(r,e,t=n){const i=[];return function r(n){for(const o of n){i.push(e(o));const n=o[t.children];Array.isArray(n)&&n.length>0&&r(n)}}(r),i}function t(r,e,t=n){const i=[];return function r(n,o=0){n.forEach((n,o)=>{e(n,o)&&i.push(n);const f=n[t.children];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;const r=n[t.children];if(Array.isArray(r)&&r.length>0){const n=i(r,e,t);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;const n=o[i.children];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;const n=o[i.children];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];return!!(Array.isArray(r)&&r.length>0)&&(r.pop(),!0)}const n=i[t.children];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];return!!(Array.isArray(r)&&r.length>0)&&(r.shift(),!0)}const n=i[t.children];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;const r=n[t.children];if(Array.isArray(r)&&r.length>0&&s(r,e,t))return!0}return!1}function l(r,e,t=n){for(const n of r){if(!e(n))return!1;const r=n[t.children];if(Array.isArray(r)&&r.length>0&&!l(r,e,t))return!1}return!0}function h(r,e,t,i=n){const o=function r(n){for(const t of n){if(t[i.id]===e)return t;const n=t[i.children];if(Array.isArray(n)&&n.length>0){const e=r(n);if(e)return e}}return null}(r);if(!o)return null;const f=o[i.children];if(!Array.isArray(f)||0===f.length)return null;const c=t>=0?t:f.length+t;return c>=0&&c<f.length?f[c]:null}function d(r,e,t=n){return function r(n,i=[]){for(let o=0;o<n.length;o++){const f=n[o],c=[...i,o];if(f[t.id]===e)return c;const u=f[t.children];if(Array.isArray(u)&&u.length>0){const n=r(u,c);if(n)return n}}return null}(r)}function a(r,e,t=n){if(!Array.isArray(e)||0===e.length)return null;let i=r;for(let r=0;r<e.length;r++){const n=e[r];if(!Array.isArray(i)||n<0||n>=i.length)return null;const o=i[n];if(r===e.length-1)return o;const f=o[t.children];if(!Array.isArray(f))return null;i=f}return null}function y(r,e=n){const t={};return function r(n,i=1){for(const o of n){t[o[e.id]]=i;const n=o[e.children];Array.isArray(n)&&n.length>0&&r(n,i+1)}}(r),t}function A(r,e,t=n){const i=new Set;return function r(n){const o=[];for(const f of n){const n=f[e];if(null!=n){if(i.has(n))continue;i.add(n)}const c={...f},u=f[t.children];Array.isArray(u)&&u.length>0&&(c[t.children]=r(u)),o.push(c)}return o}(r)}const T={mapTree:e,filterTree:t,findTree:i,pushTree:o,unshiftTree:f,popTree:c,shiftTree:u,someTree:s,everyTree:l,atTree:h,indexOfTree:d,atIndexOfTree:a,nodeDepthMap:y,dedupTree:A};r.atIndexOfTree=a,r.atTree=h,r.dedupTree=A,r.default=T,r.everyTree=l,r.filterTree=t,r.findTree=i,r.indexOfTree=d,r.mapTree=e,r.nodeDepthMap=y,r.popTree=c,r.pushTree=o,r.shiftTree=u,r.someTree=s,r.unshiftTree=f,Object.defineProperty(r,"__esModule",{value:!0})});
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tree-processor",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Use array methods to process tree-structured data",
|
|
5
|
+
"main": "dist/tree-processor.cjs.js",
|
|
6
|
+
"module": "dist/tree-processor.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/tree-processor.esm.js",
|
|
13
|
+
"require": "./dist/tree-processor.cjs.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "rollup -c",
|
|
24
|
+
"test": "vitest",
|
|
25
|
+
"test:coverage": "vitest --coverage",
|
|
26
|
+
"size:dist": "node scripts/check-size.js",
|
|
27
|
+
"size:src": "node scripts/check-src-size.js",
|
|
28
|
+
"size:all": "npm run size:src && npm run size:dist",
|
|
29
|
+
"prepublishOnly": "npm run build"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"tree",
|
|
33
|
+
"array",
|
|
34
|
+
"map",
|
|
35
|
+
"find",
|
|
36
|
+
"filter",
|
|
37
|
+
"push",
|
|
38
|
+
"unshift",
|
|
39
|
+
"pop",
|
|
40
|
+
"shift",
|
|
41
|
+
"some",
|
|
42
|
+
"every",
|
|
43
|
+
"at",
|
|
44
|
+
"indexOf",
|
|
45
|
+
"deduplication",
|
|
46
|
+
"tree-processor"
|
|
47
|
+
],
|
|
48
|
+
"author": "",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": ""
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
|
56
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
57
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
58
|
+
"@rollup/plugin-typescript": "^12.1.0",
|
|
59
|
+
"@types/node": "^22.10.2",
|
|
60
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
61
|
+
"rollup": "^4.24.0",
|
|
62
|
+
"rollup-plugin-visualizer": "^6.0.5",
|
|
63
|
+
"terser": "^5.36.0",
|
|
64
|
+
"tslib": "^2.8.1",
|
|
65
|
+
"typescript": "^5.7.2",
|
|
66
|
+
"vitest": "^2.1.8"
|
|
67
|
+
}
|
|
68
|
+
}
|