vmo-tree 0.0.1 → 0.0.2
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/dist/vmo-tree.js +27 -30
- package/dist/vmo-tree.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/vmo-tree.js
CHANGED
@@ -27,7 +27,7 @@ function x(t) {
|
|
27
27
|
}
|
28
28
|
};
|
29
29
|
}
|
30
|
-
function
|
30
|
+
function d(t) {
|
31
31
|
for (var r = [], e; !(e = t.next()).done; )
|
32
32
|
r.push(e.value);
|
33
33
|
return r;
|
@@ -61,7 +61,7 @@ var E = Object.prototype.toString, F = /* @__PURE__ */ function() {
|
|
61
61
|
const R = F;
|
62
62
|
var $ = !/* @__PURE__ */ {
|
63
63
|
toString: null
|
64
|
-
}.propertyIsEnumerable("toString"),
|
64
|
+
}.propertyIsEnumerable("toString"), p = ["constructor", "valueOf", "isPrototypeOf", "toString", "propertyIsEnumerable", "hasOwnProperty", "toLocaleString"], I = /* @__PURE__ */ function() {
|
65
65
|
return arguments.propertyIsEnumerable("length");
|
66
66
|
}(), B = function(r, e) {
|
67
67
|
for (var n = 0; n < r.length; ) {
|
@@ -70,17 +70,17 @@ var $ = !/* @__PURE__ */ {
|
|
70
70
|
n += 1;
|
71
71
|
}
|
72
72
|
return !1;
|
73
|
-
}, M = /* @__PURE__ */ y(typeof Object.keys == "function" && !
|
73
|
+
}, M = /* @__PURE__ */ y(typeof Object.keys == "function" && !I ? function(r) {
|
74
74
|
return Object(r) !== r ? [] : Object.keys(r);
|
75
75
|
} : function(r) {
|
76
76
|
if (Object(r) !== r)
|
77
77
|
return [];
|
78
|
-
var e, n, s = [], c =
|
78
|
+
var e, n, s = [], c = I && R(r);
|
79
79
|
for (e in r)
|
80
80
|
g(e, r) && (!c || e !== "length") && (s[s.length] = e);
|
81
81
|
if ($)
|
82
|
-
for (n =
|
83
|
-
e =
|
82
|
+
for (n = p.length - 1; n >= 0; )
|
83
|
+
e = p[n], g(e, r) && !B(s, e) && (s[s.length] = e), n -= 1;
|
84
84
|
return s;
|
85
85
|
});
|
86
86
|
const S = M;
|
@@ -88,16 +88,16 @@ var z = /* @__PURE__ */ y(function(r) {
|
|
88
88
|
return r === null ? "Null" : r === void 0 ? "Undefined" : Object.prototype.toString.call(r).slice(8, -1);
|
89
89
|
});
|
90
90
|
const m = z;
|
91
|
-
function
|
92
|
-
var s =
|
91
|
+
function b(t, r, e, n) {
|
92
|
+
var s = d(t), c = d(r);
|
93
93
|
function u(a, i) {
|
94
|
-
return
|
94
|
+
return w(a, i, e.slice(), n.slice());
|
95
95
|
}
|
96
96
|
return !q(function(a, i) {
|
97
97
|
return !q(u, i, a);
|
98
98
|
}, c, s);
|
99
99
|
}
|
100
|
-
function
|
100
|
+
function w(t, r, e, n) {
|
101
101
|
if (v(t, r))
|
102
102
|
return !0;
|
103
103
|
var s = m(t);
|
@@ -138,9 +138,9 @@ function d(t, r, e, n) {
|
|
138
138
|
}
|
139
139
|
switch (s) {
|
140
140
|
case "Map":
|
141
|
-
return t.size !== r.size ? !1 :
|
141
|
+
return t.size !== r.size ? !1 : b(t.entries(), r.entries(), e.concat([t]), n.concat([r]));
|
142
142
|
case "Set":
|
143
|
-
return t.size !== r.size ? !1 :
|
143
|
+
return t.size !== r.size ? !1 : b(t.values(), r.values(), e.concat([t]), n.concat([r]));
|
144
144
|
case "Arguments":
|
145
145
|
case "Array":
|
146
146
|
case "Object":
|
@@ -170,14 +170,14 @@ function d(t, r, e, n) {
|
|
170
170
|
var a = e.concat([t]), i = n.concat([r]);
|
171
171
|
for (c = u.length - 1; c >= 0; ) {
|
172
172
|
var f = u[c];
|
173
|
-
if (!(g(f, r) &&
|
173
|
+
if (!(g(f, r) && w(r[f], t[f], a, i)))
|
174
174
|
return !1;
|
175
175
|
c -= 1;
|
176
176
|
}
|
177
177
|
return !0;
|
178
178
|
}
|
179
179
|
var D = /* @__PURE__ */ x(function(r, e) {
|
180
|
-
return
|
180
|
+
return w(r, e, [], []);
|
181
181
|
});
|
182
182
|
const O = D;
|
183
183
|
var K = /* @__PURE__ */ y(function(r) {
|
@@ -187,7 +187,7 @@ const L = K;
|
|
187
187
|
function W(t) {
|
188
188
|
return new RegExp(t.source, t.flags ? t.flags : (t.global ? "g" : "") + (t.ignoreCase ? "i" : "") + (t.multiline ? "m" : "") + (t.sticky ? "y" : "") + (t.unicode ? "u" : "") + (t.dotAll ? "s" : ""));
|
189
189
|
}
|
190
|
-
function
|
190
|
+
function o(t, r, e) {
|
191
191
|
if (e || (e = new H()), G(t))
|
192
192
|
return t;
|
193
193
|
var n = function(c) {
|
@@ -196,7 +196,7 @@ function b(t, r, e) {
|
|
196
196
|
return u;
|
197
197
|
e.set(t, c);
|
198
198
|
for (var a in t)
|
199
|
-
Object.prototype.hasOwnProperty.call(t, a) && (c[a] = r ?
|
199
|
+
Object.prototype.hasOwnProperty.call(t, a) && (c[a] = r ? o(t[a], !0, e) : t[a]);
|
200
200
|
return c;
|
201
201
|
};
|
202
202
|
switch (m(t)) {
|
@@ -259,21 +259,21 @@ var H = /* @__PURE__ */ function() {
|
|
259
259
|
}
|
260
260
|
}, t;
|
261
261
|
}(), J = /* @__PURE__ */ y(function(r) {
|
262
|
-
return r != null && typeof r.clone == "function" ? r.clone() :
|
262
|
+
return r != null && typeof r.clone == "function" ? r.clone() : o(r, !0);
|
263
263
|
});
|
264
|
-
const
|
264
|
+
const k = J;
|
265
265
|
var Q = /* @__PURE__ */ x(function(r, e) {
|
266
266
|
for (var n = {}, s = 0; s < r.length; )
|
267
267
|
r[s] in e && (n[r[s]] = e[r[s]]), s += 1;
|
268
268
|
return n;
|
269
269
|
});
|
270
270
|
const _ = Q;
|
271
|
-
function
|
271
|
+
function j(t, r, e, n = [], s = void 0) {
|
272
272
|
if (n.push(r), O(t, _(Object.keys(t), r)) || s === r)
|
273
273
|
return n;
|
274
274
|
if (Array.isArray(r[e]))
|
275
275
|
for (let c of r[e]) {
|
276
|
-
const u =
|
276
|
+
const u = j(t, c, e, n, r);
|
277
277
|
if (u)
|
278
278
|
return u;
|
279
279
|
}
|
@@ -330,10 +330,10 @@ class l extends Array {
|
|
330
330
|
static path(r, e, n, s = !0) {
|
331
331
|
const c = Array.isArray(e), u = c ? { [n]: e } : e, a = c ? e : [e], i = s ? [l.find(r, a, n, s)].filter((f) => f != null) : l.find(r, a, n, s);
|
332
332
|
return s ? i.map((f) => {
|
333
|
-
const h =
|
333
|
+
const h = j(f, u, n, []);
|
334
334
|
return c && (h == null || h.shift()), h;
|
335
335
|
})[0] ?? [] : i.map((f) => {
|
336
|
-
const h =
|
336
|
+
const h = j(f, u, n, []);
|
337
337
|
return c && (h == null || h.shift()), h;
|
338
338
|
});
|
339
339
|
}
|
@@ -346,7 +346,7 @@ class l extends Array {
|
|
346
346
|
* @returns {T[]}
|
347
347
|
*/
|
348
348
|
static filter(r, e, n, s = !0) {
|
349
|
-
return
|
349
|
+
return k(e).filter((u, a, i) => {
|
350
350
|
if (s)
|
351
351
|
return Array.isArray(u[n]) && (u[n] = l.filter(
|
352
352
|
r,
|
@@ -374,7 +374,7 @@ class l extends Array {
|
|
374
374
|
* @returns {T[]}
|
375
375
|
*/
|
376
376
|
static map(r, e, n, s = !0) {
|
377
|
-
return [].map.bind(
|
377
|
+
return [].map.bind(k(e))((u, a, i) => {
|
378
378
|
if (s)
|
379
379
|
return Array.isArray(u[n]) && (u[n] = l.map(r, u[n], n)), r(u, a, i);
|
380
380
|
{
|
@@ -434,7 +434,7 @@ class l extends Array {
|
|
434
434
|
* @returns {VmoTree<T>}
|
435
435
|
*/
|
436
436
|
constructor(r, e) {
|
437
|
-
if (!r || Array.isArray(r))
|
437
|
+
if (!r || Array.isArray(r))
|
438
438
|
r ? super(...r) : super(), Object.defineProperty(this, "_nodeKey", {
|
439
439
|
value: (e == null ? void 0 : e.nodeKey) ?? "id",
|
440
440
|
writable: !0,
|
@@ -454,11 +454,8 @@ class l extends Array {
|
|
454
454
|
// 设置为不可枚举
|
455
455
|
configurable: !0
|
456
456
|
});
|
457
|
-
|
458
|
-
|
459
|
-
throw Error(
|
460
|
-
'The constructor of VmoTree requires parameters " new VmoTree(array?: T[], childrenKey?: string)", the current type is incorrect! '
|
461
|
-
);
|
457
|
+
else
|
458
|
+
throw Error("The constructor of VmoTree requires parameters, but the current parameters type is incorrect!");
|
462
459
|
}
|
463
460
|
/**
|
464
461
|
* 实例查找方法
|
package/dist/vmo-tree.umd.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
(function(A,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(A=typeof globalThis<"u"?globalThis:A||self,v(A["vmo-tree"]={}))})(this,function(A){"use strict";const v={"@@functional/placeholder":!0};function g(t){return t===v}function y(t){return function r(e){return arguments.length===0||g(e)?r:t.apply(this,arguments)}}function
|
1
|
+
(function(A,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(A=typeof globalThis<"u"?globalThis:A||self,v(A["vmo-tree"]={}))})(this,function(A){"use strict";const v={"@@functional/placeholder":!0};function g(t){return t===v}function y(t){return function r(e){return arguments.length===0||g(e)?r:t.apply(this,arguments)}}function w(t){return function r(e,n){switch(arguments.length){case 0:return r;case 1:return g(e)?r:y(function(s){return t(e,s)});default:return g(e)&&g(n)?r:g(e)?y(function(s){return t(s,n)}):g(n)?y(function(s){return t(e,s)}):t(e,n)}}}function q(t){for(var r=[],e;!(e=t.next()).done;)r.push(e.value);return r}function E(t,r,e){for(var n=0,s=e.length;n<s;){if(t(r,e[n]))return!0;n+=1}return!1}function C(t){var r=String(t).match(/^function (\w*)/);return r==null?"":r[1]}function m(t,r){return Object.prototype.hasOwnProperty.call(r,t)}function F(t,r){return t===r?t!==0||1/t===1/r:t!==t&&r!==r}const O=typeof Object.is=="function"?Object.is:F;var I=Object.prototype.toString,R=function(){return I.call(arguments)==="[object Arguments]"?function(r){return I.call(r)==="[object Arguments]"}:function(r){return m("callee",r)}}();const $=R;var M=!{toString:null}.propertyIsEnumerable("toString"),b=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],S=function(){return arguments.propertyIsEnumerable("length")}(),B=function(r,e){for(var n=0;n<r.length;){if(r[n]===e)return!0;n+=1}return!1},z=y(typeof Object.keys=="function"&&!S?function(r){return Object(r)!==r?[]:Object.keys(r)}:function(r){if(Object(r)!==r)return[];var e,n,s=[],c=S&&$(r);for(e in r)m(e,r)&&(!c||e!=="length")&&(s[s.length]=e);if(M)for(n=b.length-1;n>=0;)e=b[n],m(e,r)&&!B(s,e)&&(s[s.length]=e),n-=1;return s});const x=z;var D=y(function(r){return r===null?"Null":r===void 0?"Undefined":Object.prototype.toString.call(r).slice(8,-1)});const d=D;function k(t,r,e,n){var s=q(t),c=q(r);function u(a,i){return _(a,i,e.slice(),n.slice())}return!E(function(a,i){return!E(u,i,a)},c,s)}function _(t,r,e,n){if(O(t,r))return!0;var s=d(t);if(s!==d(r))return!1;if(typeof t["fantasy-land/equals"]=="function"||typeof r["fantasy-land/equals"]=="function")return typeof t["fantasy-land/equals"]=="function"&&t["fantasy-land/equals"](r)&&typeof r["fantasy-land/equals"]=="function"&&r["fantasy-land/equals"](t);if(typeof t.equals=="function"||typeof r.equals=="function")return typeof t.equals=="function"&&t.equals(r)&&typeof r.equals=="function"&&r.equals(t);switch(s){case"Arguments":case"Array":case"Object":if(typeof t.constructor=="function"&&C(t.constructor)==="Promise")return t===r;break;case"Boolean":case"Number":case"String":if(!(typeof t==typeof r&&O(t.valueOf(),r.valueOf())))return!1;break;case"Date":if(!O(t.valueOf(),r.valueOf()))return!1;break;case"Error":return t.name===r.name&&t.message===r.message;case"RegExp":if(!(t.source===r.source&&t.global===r.global&&t.ignoreCase===r.ignoreCase&&t.multiline===r.multiline&&t.sticky===r.sticky&&t.unicode===r.unicode))return!1;break}for(var c=e.length-1;c>=0;){if(e[c]===t)return n[c]===r;c-=1}switch(s){case"Map":return t.size!==r.size?!1:k(t.entries(),r.entries(),e.concat([t]),n.concat([r]));case"Set":return t.size!==r.size?!1:k(t.values(),r.values(),e.concat([t]),n.concat([r]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var u=x(t);if(u.length!==x(r).length)return!1;var a=e.concat([t]),i=n.concat([r]);for(c=u.length-1;c>=0;){var f=u[c];if(!(m(f,r)&&_(r[f],t[f],a,i)))return!1;c-=1}return!0}var K=w(function(r,e){return _(r,e,[],[])});const o=K;var L=y(function(r){return r==null});const W=L;function G(t){return new RegExp(t.source,t.flags?t.flags:(t.global?"g":"")+(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.sticky?"y":"")+(t.unicode?"u":"")+(t.dotAll?"s":""))}function P(t,r,e){if(e||(e=new J),H(t))return t;var n=function(c){var u=e.get(t);if(u)return u;e.set(t,c);for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(c[a]=r?P(t[a],!0,e):t[a]);return c};switch(d(t)){case"Object":return n(Object.create(Object.getPrototypeOf(t)));case"Array":return n(Array(t.length));case"Date":return new Date(t.valueOf());case"RegExp":return G(t);case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"BigInt64Array":case"BigUint64Array":return t.slice();default:return t}}function H(t){var r=typeof t;return t==null||r!="object"&&r!="function"}var J=function(){function t(){this.map={},this.length=0}return t.prototype.set=function(r,e){var n=this.hash(r),s=this.map[n];s||(this.map[n]=s=[]),s.push([r,e]),this.length+=1},t.prototype.hash=function(r){var e=[];for(var n in r)e.push(Object.prototype.toString.call(r[n]));return e.join()},t.prototype.get=function(r){if(this.length<=180){for(var e in this.map)for(var u=this.map[e],n=0;n<u.length;n+=1){var s=u[n];if(s[0]===r)return s[1]}return}var c=this.hash(r),u=this.map[c];if(u)for(var n=0;n<u.length;n+=1){var s=u[n];if(s[0]===r)return s[1]}},t}(),Q=y(function(r){return r!=null&&typeof r.clone=="function"?r.clone():P(r,!0)});const U=Q;var X=w(function(r,e){for(var n={},s=0;s<r.length;)r[s]in e&&(n[r[s]]=e[r[s]]),s+=1;return n});const j=X;function p(t,r,e,n=[],s=void 0){if(n.push(r),o(t,j(Object.keys(t),r))||s===r)return n;if(Array.isArray(r[e]))for(let c of r[e]){const u=p(t,c,e,n,r);if(u)return u}return n.pop(),null}class l extends Array{static array2Tree(r,e="id",n="parentId",s="children",c=!1){let u=[];const a={},i={};return r.forEach(f=>{i[f[e]]={...f,[s]:[]},W(f[n])?u.push(i[f[e]]):i[f[n]]?i[f[n]][s].push(i[f[e]]):a[f[n]]?a[f[n]].push(i[f[e]]):a[f[n]]=[i[f[e]]],a[f[e]]&&(i[f[e]][s]=a[f[e]],delete a[f[e]])}),c&&Object.keys(a).length>0&&Object.keys(a).forEach(f=>{u=u.concat(a[f])}),l.treeFrom(u,e,n,s)}static flatten2Array(r,e="id",n="parentId",s="children"){const c=[],u=[];for(r.forEach(a=>{u.push({node:a,parent:void 0})});u.length>0;){const{node:a,parent:i}=u.pop(),f={...a};delete f[s],i&&(f[n]=i),c.push(f),Array.isArray(a[s])&&a[s].forEach(h=>{u.unshift({node:h,parent:a[e]})})}return c}static path(r,e,n,s=!0){const c=Array.isArray(e),u=c?{[n]:e}:e,a=c?e:[e],i=s?[l.find(r,a,n,s)].filter(f=>f!=null):l.find(r,a,n,s);return s?i.map(f=>{const h=p(f,u,n,[]);return c&&(h==null||h.shift()),h})[0]??[]:i.map(f=>{const h=p(f,u,n,[]);return c&&(h==null||h.shift()),h})}static filter(r,e,n,s=!0){return U(e).filter((u,a,i)=>{if(s)return Array.isArray(u[n])&&(u[n]=l.filter(r,u[n],n,s)),r(u,a,i);{const f=r(u,a,i);return Array.isArray(u[n])&&(u[n]=l.filter(r,u[n],n,s)),f}})}static map(r,e,n,s=!0){return[].map.bind(U(e))((u,a,i)=>{if(s)return Array.isArray(u[n])&&(u[n]=l.map(r,u[n],n)),r(u,a,i);{const f=r(u,a,i);return Array.isArray(f[n])&&(f[n]=l.map(r,f[n],n)),f}})}static find(r,e,n,s=!0){if(s){for(let c in e){if(typeof r=="function"?r(e[c]):o(r,j(Object.keys(r),e[c])))return e[c];const u=e[c][n],a=Array.isArray(u)?l.find(r,u,n):null;if(a)return a}return null}else{let c=[];for(let u in e){(typeof r=="function"?r(e[u]):o(r,j(Object.keys(r),e[u])))&&c.push(e[u]);const a=e[u][n],i=Array.isArray(a)?l.find(r,a,n,s):[];i&&(c=c.concat(i))}return c}}static treeFrom(r,e,n,s){return new l(r,{nodeKey:e,parentKey:n,childrenKey:s})}constructor(r,e){if(!r||Array.isArray(r))r?super(...r):super(),Object.defineProperty(this,"_nodeKey",{value:(e==null?void 0:e.nodeKey)??"id",writable:!0,enumerable:!1,configurable:!0}),Object.defineProperty(this,"_parentKey",{value:(e==null?void 0:e.parentKey)??"parentId",writable:!0,enumerable:!1,configurable:!0}),Object.defineProperty(this,"_childrenKey",{value:(e==null?void 0:e.childrenKey)??"children",writable:!0,enumerable:!1,configurable:!0});else throw Error("The constructor of VmoTree requires parameters, but the current parameters type is incorrect!")}find(r,e){return l.find(r,this,(e==null?void 0:e.childrenKey)??this._childrenKey,e==null?void 0:e.pickFirst)}map(r,e){return l.treeFrom(l.map(r,this,(e==null?void 0:e.childrenKey)??this._childrenKey,e==null?void 0:e.prioritizeChildren),this._nodeKey,this._parentKey,(e==null?void 0:e.childrenKey)??this._childrenKey)}filter(r,e){return l.treeFrom(l.filter(r,this,(e==null?void 0:e.childrenKey)??this._childrenKey,e==null?void 0:e.prioritizeChildren),this._nodeKey,this._parentKey,(e==null?void 0:e.childrenKey)??this._chidlrenKey)}path(r,e){return l.path(r,this,(e==null?void 0:e.childrenKey)??this._childrenKey,e==null?void 0:e.pickFirst)}flatten(r){return l.flatten2Array(this,(r==null?void 0:r.nodeKey)??this._nodeKey,(r==null?void 0:r.parentKey)??this._parentKey,(r==null?void 0:r.childrenKey)??this._childrenKey)}setConfig(r){const e=this;e._nodeKey=(r==null?void 0:r.nodeKey)??e._nodeKey??"id",e._parentKey=(r==null?void 0:r.parentKey)??e._parentKey??"parentId",e._childrenKey=(r==null?void 0:r.childrenKey)??e._childrenKey??"children"}getConfig(){return{nodeKey:this._nodeKey,parentKey:this._parentKey,childrenKey:this._childrenKey}}}A.VmoTree=l,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "vmo-tree",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.2",
|
4
4
|
"type": "module",
|
5
5
|
"private": false,
|
6
6
|
"description": "A lightweight JavaScript library for creating and maintaining tree structures, providing easy methods for manipulation, traversal, and search.",
|