esexts 1.2.8 → 1.3.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/dist/esexts.js CHANGED
@@ -8,8 +8,8 @@ function p(t = { array: !1 }) {
8
8
  if (o === "[object Array]")
9
9
  return t.array ? i.concat(...s) : s;
10
10
  if (o === "[object Object]") {
11
- for (const a in s)
12
- i[a] = u(i[a], s[a]);
11
+ for (const c in s)
12
+ i[c] = u(i[c], s[c]);
13
13
  return i;
14
14
  } else
15
15
  return s;
@@ -140,8 +140,8 @@ l(Object.prototype, {
140
140
  value: function(t = !1, e = -1, r = "children") {
141
141
  const u = [], i = (s, o, f) => {
142
142
  if (o && u.push(s), !(f == 0 || !s[r] || s[r].length == 0))
143
- for (const a of s[r])
144
- i(a, !0, f - 1);
143
+ for (const c of s[r])
144
+ i(c, !0, f - 1);
145
145
  };
146
146
  return i(this, t, e), u;
147
147
  },
@@ -252,7 +252,7 @@ l(Number.prototype, {
252
252
  l(BigInt.prototype, {
253
253
  toJSON: {
254
254
  value: function() {
255
- return this > 9007199254740991n || this < -9007199254740991n ? this.toString() : Number(this);
255
+ return this < BigInt(Number.MIN_SAFE_INTEGER) || this > BigInt(Number.MAX_SAFE_INTEGER) ? this.toString() : Number(this);
256
256
  },
257
257
  ...n
258
258
  }
@@ -647,26 +647,27 @@ l(Array.prototype, {
647
647
  // ====== Tree ======
648
648
  toTree: {
649
649
  value: function(t = {}) {
650
- const { id: e = "id", pid: r = "pid", level: u = "level", root: i = "root", parent: s = "parent", children: o = "children", empty: f = null, hasRoot: a = !0 } = t, v = this.toObject((h) => [h[e], h]), c = this.toGroup((h) => [h[r], h]), g = this.length && a ? this.find((h) => h[r] === 0) : { [e]: 0, [r]: -1, [i]: null, [s]: null, [o]: c[0] };
651
- l(g, { [i]: { value: g, enumerable: !1, configurable: !0, writable: !0 } });
650
+ const { id: e = "id", pid: r = "pid", level: u = "level", root: i = "root", parent: s = "parent", children: o = "children", empty: f = null, hasRoot: c = !0 } = t, v = this.toObject((h) => [h[e], h]), g = this.toGroup((h) => [h[r], h]), a = this.length && c ? this.find((h) => h[r] === 0) : { [e]: 0, [r]: -1, [i]: null, [s]: null, [o]: g[0] };
651
+ l(a, { [i]: { value: a, enumerable: !1, configurable: !0, writable: !0 } });
652
652
  for (const h of this)
653
653
  l(h, {
654
- [i]: { value: g, enumerable: !1, configurable: !0, writable: !0 },
654
+ [i]: { value: a, enumerable: !1, configurable: !0, writable: !0 },
655
655
  [s]: { value: v[h[r]], enumerable: !1, configurable: !0, writable: !0 }
656
- }), h[o] = c[h[e]] || f;
657
- return g.treeEach0((h) => h[u] = h[s] ? h[s][u] + 1 : 0, -1, o), g;
656
+ }), h[o] = g[h[e]] || f;
657
+ return a.treeEach0((h) => h[u] = h[s] ? h[s][u] + 1 : 0, -1, o), a;
658
658
  },
659
659
  ...n
660
660
  },
661
661
  tree2tree: {
662
662
  value: function(t = {}, e = null, r = null) {
663
- const { id: u = "id", pid: i = "pid", level: s = "level", root: o = "root", parent: f = "parent", children: a = "children", empty: v = null } = t;
664
- e = e || { [u]: 0, [i]: -1, [s]: 0, [o]: null, [f]: null, [a]: this }, r = r || e;
665
- for (const c of this)
666
- l(c, {
663
+ var g;
664
+ const { id: u = "id", pid: i = "pid", level: s = "level", root: o = "root", parent: f = "parent", children: c = "children", empty: v = null } = t;
665
+ e = e || { [u]: 0, [i]: -1, [s]: 0, [o]: null, [f]: null, [c]: this }, r = r || e;
666
+ for (const a of this)
667
+ l(a, {
667
668
  [o]: { value: e, enumerable: !1, configurable: !0, writable: !0 },
668
669
  [f]: { value: r, enumerable: !1, configurable: !0, writable: !0 }
669
- }), c[i] = r[u], c[s] = r[s] + 1, c[a] = c[a] && c[a].length ? c[a] : v, c[a]?.tree2tree(t, e, c);
670
+ }), a[i] = r[u], a[s] = r[s] + 1, a[c] = a[c] && a[c].length ? a[c] : v, (g = a[c]) == null || g.tree2tree(t, e, a);
670
671
  return e;
671
672
  },
672
673
  ...n
@@ -1 +1 @@
1
- (function(l){typeof define=="function"&&define.amd?define(l):l()})(function(){"use strict";const l=Object.defineProperties,n={enumerable:!1,configurable:!0,writable:!0};function p(t={array:!1}){return function(e={},...r){const u=(i,s)=>{const o=Object.prototype.toString.call(i),f=Object.prototype.toString.call(s);if(o!==f)return s;if(o==="[object Array]")return t.array?i.concat(...s):s;if(o==="[object Object]"){for(const a in s)i[a]=u(i[a],s[a]);return i}else return s};for(const i of r)e=u(e,i);return e}}const d=p({array:!1}),b=p({array:!0});l(Object,{isObject:{value:function(t){return Object.prototype.toString.call(t)==="[object Object]"},...n},merge0:{value:function(...t){return d(this,...t)},...n},concat0:{value:function(...t){return b(this,...t)},...n}}),l(Object.prototype,{clone0:{value:function(){return JSON.parse(JSON.stringify(this))},...n},length0:{value:function(){return Object.keys(this).length},...n},entries0:{value:function(){return Object.entries(this)},...n},keys0:{value:function(){return Object.keys(this)},...n},values0:{value:function(){return Object.values(this)},...n},merge0:{value:function(...t){return d(this,...t)},...n},concat0:{value:function(...t){return b(this,...t)},...n},map0:{value:function(t=(r,u,i)=>[r,u],e=0){return Object.entries(this).map(([r,u])=>t(r,u,e++))},...n},pick0:{value:function(...t){const e={};for(const r of t)e[r]=this[r];return e},...n},omit0:{value:function(...t){const e={},r=new Set(t);for(const u in this)r.has(u)||(e[u]=this[u]);return e},...n},attr0:{value:function(t,...e){return typeof this!="object"?this:typeof t=="function"?t(this,...e):this[t]},...n},log0:{value:function(...t){return console.log(...t,this),this},...n},debug0:{value:function(...t){return console.debug(...t,this),this},...n},getParents0:{value:function(t=!1,e=-1,r="parent"){const u=t?[this]:[];let i=this[r];for(;i&&e--!=0;)u.push(i),i=i[r];return u},...n},getChildrens0:{value:function(t=!1,e=-1,r="children"){const u=[],i=(s,o,f)=>{if(o&&u.push(s),!(f==0||!s[r]||s[r].length==0))for(const a of s[r])i(a,!0,f-1)};return i(this,t,e),u},...n},treeFind0:{value:function(t,e=!0,r=-1,u="children"){if(e&&t(this))return this;if(r==0||!this[u]||this[u].length==0)return null;for(const i of this[u]){const s=i.treeFind0(t,!0,r-1,u);if(s!==null)return s}return null},...n},treeEach0:{value:function(t,e=!0,r=-1,u="children"){if(e&&t(this),!(r==0||!this[u]||this[u].length==0)){for(const i of this[u])i.treeEach0(t,!0,r-1,u);return this}},...n},treeMap0:{value:function(t,e=!0,r=-1,u="children",i=null){const s=e?t(this):this,o=[];if(r==0||!this[u]||this[u].length==0)return s;for(const f of this[u])o.push(f.treeMap0(t,!0,r-1,u,i));return s[u]=o,s},...n}}),l(Number.prototype,{ceil:{value:function(){return Math.ceil(this)},...n},floor:{value:function(){return Math.floor(this)},...n},round:{value:function(t=0){return t==0?Math.round(this):Math.round(this*10**t)/10**t},...n},trunc:{value:function(){return Math.trunc(this)},...n},abs:{value:function(){return Math.abs(this)},...n},max:{value:function(...t){return Math.max(this,...t)},...n},min:{value:function(...t){return Math.min(this,...t)},...n},baseConvert:{value:function(t=64){let e="",r=this,u="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";for(;r>0;)e=u.at(r%t)+e,r=Math.floor(r/t);return e||"0"},...n},toFixed0:{value:function(...t){return+this.toFixed(...t)},...n},toDate:{value:function(){return Date.new(this)},...n}}),l(BigInt.prototype,{toJSON:{value:function(){return this>9007199254740991n||this<-9007199254740991n?this.toString():Number(this)},...n}}),l(String.prototype,{length0:{value:function(){return this.length},...n},substring0:{value:function(t=0,e=this.length){return t=t>=0?t:this.length+t,e=e>=0?e:this.length+e,this.substring(t,e)},...n},substr0:{value:function(t=0,e=this.length){return t=t>=0?t:this.length+t,e=t+e,this.substring(t,e)},...n},split0:{value:function(t=",",e=-1){const r=this?this.split(t):[];return e===-1?r:r.push0(r.splice(e-1).join(t))},...n},splitNumber:{value:function(t=","){return this.split0(t).map(e=>+e)},...n},splitSegment:{value:function(t=1){const e=[];for(let r=0;r<this.length;r+=t)e.push(this.substring(r,t));return e},...n},sprintf:{value:function(...t){let[e,...r]=this.split(/%[sd]/);for(let u=0;u<r.length;u++)e+=t[u]+r[u];return e},...n},subOf:{value:function(t,e,r=0,u=0){for(let o=0;o<r&&u!=-1;o++,u++)u=this.indexOf(t,u);let i=this.indexOf(t,u),s=this.indexOf(e,i);return i==-1||s==-1?"":(i+=t.length,this.substring(i,s))},...n},lastSubOf:{value:function(t,e,r=0,u=1/0){for(let o=0;o<r&&u!=-1;o++,u--)u=this.lastIndexOf(t,u);let i=this.lastIndexOf(t,u),s=this.indexOf(e,i);return i==-1||s==-1?"":(i+=t.length,this.substring(i,s))},...n},camel2under:{value:function(){return this.substr(0,1).toLowerCase()+this.substr(1).replace(/([A-Z])/g,(t,e)=>"_"+e.toLowerCase())},...n},under2camel:{value:function(){return this.replace(/_([a-z])/g,(t,e)=>e.toUpperCase())},...n},camel2pascal:{value:function(){return this.substr(0,1).toUpperCase()+this.substr(1)},...n},pascal2camel:{value:function(){return this.substr(0,1).toLowerCase()+this.substr(1)},...n},under2kebab:{value:function(){return this.replace(/_/g,"-")},...n},kebab2under:{value:function(){return this.replace(/-/g,"_")},...n},baseConvert:{value:function(t=64){let e=0,r="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";for(let u=0;u<this.length;u++)e=e*t+r.indexOf(this.at(u));return e},...n},toFixed0:{value:function(...t){return+(+this).toFixed(...t)},...n},toDate:{value:function(){return Date.new(this)},...n},hex2bytes:{value:function(){const t=[];for(let e=0;e<this.length;e+=2)t.push(Number.parseInt(this.substring(e,e+2),16));return t},...n},string2bytes:{value:function(){if(typeof TextEncoder<"u")return Array.from(new TextEncoder().encode(this));const t=[],e=encodeURIComponent(this);for(let r=0;r<e.length;)t.push(e.charAt(r)=="%"?Number.parseInt(e.substring(r+1,r+=3),16):e.charCodeAt(r++));return t},...n},base64decode:{value:function(t){const e=[],r={},u=t===!0?"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let s=0;s<u.length;s++)r[u.charAt(s)]=s;const i=this.charAt(this.length-1)!="="?this.length:this.charAt(this.length-2)!="="?this.length-1:this.length-2;for(let s=3;s<i;s+=4){const o=(r[this.charAt(s-3)]<<18)+(r[this.charAt(s-2)]<<12)+(r[this.charAt(s-1)]<<6)+r[this.charAt(s)];e.push((o&16711680)>>16,(o&65280)>>8,o&255)}if(i%4==3){const s=(r[this.charAt(i-3)]<<18)+(r[this.charAt(i-2)]<<12)+(r[this.charAt(i-1)]<<6);e.push((s&16711680)>>16,(s&65280)>>8)}else if(i%4==2){const s=(r[this.charAt(i-2)]<<18)+(r[this.charAt(i-1)]<<12);e.push((s&16711680)>>16)}return e},...n}}),typeof Iterator<"u"&&l(Iterator.prototype,{toArray:{value:function(){return Array.from(this)},...n}}),l(Array.prototype,{length0:{value:function(){return this.length},...n},entries0:{value:function(){return this.entries()},...n},push0:{value:function(...t){return this.push(...t),this},...n},push1:{value:function(...t){return this.push(...t),t[0]},...n},push3:{value:function(...t){return this.push(...t),t},...n},pop0:{value:function(...t){return this.pop(...t),this},...n},pop1:{value:function(...t){return this.pop(...t),t[0]},...n},pop3:{value:function(...t){return this.pop(...t),t},...n},unshift0:{value:function(...t){return this.unshift(...t),this},...n},unshift1:{value:function(...t){return this.unshift(...t),t[0]},...n},unshift3:{value:function(...t){return this.unshift(...t),t},...n},shift0:{value:function(...t){return this.shift(...t),this},...n},shift1:{value:function(...t){return this.shift(...t),t[0]},...n},shift3:{value:function(...t){return this.shift(...t),t},...n},first0:{value:function(t=null){return this.length?this[0]:t},...n},last0:{value:function(t=null){return this.length?this[this.length-1]:t},...n},find0:{value:function(t,e=null){return this.find(t)??e},...n},equals0:{value:function(t){return this.length===t.length&&(this===t||this.length===0||this.every((e,r)=>e===t[r]))},...n},unique0:{value:function(t=e=>e){const e=new Set;return this.filter(r=>e.has(t(r))?!1:!!e.add(t(r)))},...n},each0:{value:function(t){return this.forEach(t),this},...n},toObject:{value:function(t=(e,r)=>[r,e]){return Object.fromEntries(this.map(t))},...n},toMap:{value:function(t=(e,r)=>[r,e]){return new Map(this.map(t))},...n},toSet:{value:function(){return new Set(this)},...n},toGroup:{value:function(t=e=>[e.id,e]){const e={};for(const r of this){const[u,i]=t(r);u in e||(e[u]=[]),e[u].push(i)}return e},...n},toMerge:{value:function(t=u=>u.id,e=u=>({...u,children:u.children||[]}),r=(u,i)=>u.children.push(i)){const u=[];for(const i of this)r(u.find(s=>t(s)==t(i))??u.push1(e(i)),i);return u},...n},bytes2hex:{value:function(){let t="";for(let e=0;e<this.length;e++)t+=(this[e]<16?"0":"")+this[e].toString(16);return t},...n},bytes2string:{value:function(){if(typeof TextDecoder<"u")return new TextDecoder().decode(new Uint8Array(this));let t="";for(let e=0;e<this.length;e++)t+="%"+(this[e]<16?"0":"")+this[e].toString(16);return decodeURIComponent(t)},...n},base64encode:{value:function(t=!1,e=!0){let r="",u=t===!0?"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let i=2;i<this.length;i+=3){const s=(this[i-2]<<16)+(this[i-1]<<8)+this[i];r+=u.charAt((s&16515072)>>18)+u.charAt((s&258048)>>12)+u.charAt((s&4032)>>6)+u.charAt(s&63)}if(this.length%3==2){const i=(this[this.length-2]<<16)+(this[this.length-1]<<8);r+=u.charAt((i&16515072)>>18)+u.charAt((i&258048)>>12)+u.charAt((i&4032)>>6)+(e===!1?"":"=")}else if(this.length%3==1){const i=this[this.length-1]<<16;r+=u.charAt((i&16515072)>>18)+u.charAt((i&258048)>>12)+(e===!1?"":"==")}return r},...n},toUint8Array:{value:function(){return new Uint8Array(this)},...n},assoc:{value:function(t,e,r={}){const u=this.unique0(s=>s[t]),i=u.length==0?{}:typeof r=="function"?r(u):r;return this.each0(s=>s[e]=i[s[t]]??null)},...n},toTree:{value:function(t={}){const{id:e="id",pid:r="pid",level:u="level",root:i="root",parent:s="parent",children:o="children",empty:f=null,hasRoot:a=!0}=t,v=this.toObject(h=>[h[e],h]),c=this.toGroup(h=>[h[r],h]),g=this.length&&a?this.find(h=>h[r]===0):{[e]:0,[r]:-1,[i]:null,[s]:null,[o]:c[0]};l(g,{[i]:{value:g,enumerable:!1,configurable:!0,writable:!0}});for(const h of this)l(h,{[i]:{value:g,enumerable:!1,configurable:!0,writable:!0},[s]:{value:v[h[r]],enumerable:!1,configurable:!0,writable:!0}}),h[o]=c[h[e]]||f;return g.treeEach0(h=>h[u]=h[s]?h[s][u]+1:0,-1,o),g},...n},tree2tree:{value:function(t={},e=null,r=null){const{id:u="id",pid:i="pid",level:s="level",root:o="root",parent:f="parent",children:a="children",empty:v=null}=t;e=e||{[u]:0,[i]:-1,[s]:0,[o]:null,[f]:null,[a]:this},r=r||e;for(const c of this)l(c,{[o]:{value:e,enumerable:!1,configurable:!0,writable:!0},[f]:{value:r,enumerable:!1,configurable:!0,writable:!0}}),c[i]=r[u],c[s]=r[s]+1,c[a]=c[a]&&c[a].length?c[a]:v,c[a]?.tree2tree(t,e,c);return e},...n},treeFind0:{value:function(t,e=!0,r=-1,u="children"){for(const i of this){const s=i.treeFind0(t,e,r,u);if(s!==null)return s}return null},...n},treeEach0:{value:function(t,e=!0,r=-1,u="children"){for(const i of this)i.treeEach0(t,e,r,u);return this},...n},treeMap0:{value:function(t,e=!0,r=-1,u="children",i=null){return this.map(s=>s.treeMap0(t,e,r,u,i))},...n}}),l(ArrayBuffer.prototype,{toUint8Array:{value:function(){return new Uint8Array(this)},...n}}),l(Uint8Array.prototype,{bytes2hex:{value:Array.prototype.bytes2hex,...n},bytes2string:{value:Array.prototype.bytes2string,...n},base64encode:{value:Array.prototype.base64encode,...n},toArray:{value:function(){return new Array(...this)},...n}}),l(Map.prototype,{length0:{value:function(){return this.size},...n},entries0:{value:function(){return[...this.entries()]},...n},keys0:{value:function(){return[...this.keys()]},...n},values0:{value:function(){return[...this.values()]},...n},get0:{value:function(t,e=null,...r){if(this.has(t))return this.get(t);const u=typeof e!="function"?e:e(t,...r);return this.set(t,u),u},...n},get1:{value:async function(t,e=null,...r){if(this.has(t))return this.get(t);const u=typeof e!="function"?e:await e(t,...r);return this.set(t,u),u},...n},toObject:{value:function(){return Object.fromEntries(this)},...n},toJSON:{value:function(){return[...this]},...n}}),l(Set.prototype,{length0:{value:function(){return this.size},...n},entries0:{value:function(){return this.entries()},...n},toArray:{value:function(){return[...this]},...n},toJSON:{value:function(){return[...this]},...n}}),l(Date,{new:{value:function(...t){return t.length!=1?new Date(...t):Number.isNaN(+t[0])?new Date(t[0].includes("T")?t[0]:t[0].replace(/-/g,"/")):new Date(t[0]>25e8?t[0]:t[0]*1e3)},...n},format:{value:function(t="y-m-d h:i:s"){return new Date().format(t)},...n},unix:{value:function(){return this.now()/1e3|0},...n},fromUnix:{value:function(t=0){return this.new((t||0)*1e3)},...n},expr:{value:function(t={}){return new Date().expr(t)},...n},toDayRange:{value:function(){const t=new Date,e=t.getFullYear(),r=t.getMonth(),u=t.getDate(),i=new Date(e,r,u).getTime()/1e3|0;return[i,i+86400-1]},...n},toWeekRange:{value:function(){let t=new Date;for(;t.getDay()!=1;)t=new Date(t.getTime()-86400);const e=t.getFullYear(),r=t.getMonth(),u=t.getDate(),i=new Date(e,r,u).getTime()/1e3|0;return[i,i+86400*7-1]},...n},toMonthRange:{value:function(){const t=new Date,e=t.getFullYear(),r=t.getMonth(),u=new Date(e,r,1).getTime()/1e3|0,i=new Date(e,r+1,0,23,59,59).getTime()/1e3|0;return[u,i]},...n},toYearRange:{value:function(){const e=new Date().getFullYear(),r=new Date(e,1,1).getTime()/1e3|0,u=new Date(e+1,1,0,23,59,59).getTime()/1e3|0;return[r,u]},...n}}),l(Date.prototype,{format:{value:function(t="y-m-d h:i:s"){if(this.getTime()===0)return"-";const e={y:this.getFullYear(),m:this.getMonth()+1,d:this.getDate(),h:this.getHours(),i:this.getMinutes(),s:this.getSeconds(),l:this.getMilliseconds(),e:this.getMonthDay()};return t.replace(/([ymdhisle])/ig,(r,u)=>u>="A"&&u<="Z"?e[u.toLowerCase()]:e[u].toString().padStart(u==="l"?3:2,"0"))},...n},unix:{value:function(){return this.getTime()/1e3|0},...n},isLeapYear:{value:function(){return this.getFullYear()%4===0&&this.getFullYear()%400!==0},...n},getMonthDay:{value:function(){return[31,0,31,30,31,30,31,31,30,31,30,31][this.getMonth()]||(this.isLeapYear()?29:28)},...n},expr:{value:function({y:t=0,m:e=0,d:r=0,h:u=0,i=0,s=0}){const o=new Date(this.getFullYear()+t,this.getMonth()+e+1,0);return new Date(this.getFullYear()+t,this.getMonth()+e,Math.min(o.getDate(),this.getDate())+r,this.getHours()+u,this.getMinutes()+i,this.getSeconds()+s)},...n},begin:{value:function(t=3){return new Date(...[this.getFullYear(),this.getMonth(),this.getDate(),this.getHours(),this.getMinutes(),this.getSeconds()].slice(0,t),...[this.getFullYear(),0,1,0,0,0].slice(t))},...n},end:{value:function(t=3){return new Date(...[this.getFullYear(),this.getMonth(),this.getDate(),this.getHours(),this.getMinutes(),this.getSeconds()].slice(0,t),...[this.getFullYear(),11,t<2?31:this.getMonthDay(),23,59,59].slice(t))},...n},week:{value:function(t,e=1){let r=new Date(this.getTime());for(;r.getDay()!==t;)r=new Date(r.getTime()+864e5*e);return r},...n},toJSON:{value:function(){return this.getTime()},...n}}),l(RegExp.prototype,{toJSON:{value:function(){return this.toString()},...n}}),l(Promise.prototype,{tryCatch:{value:function(){return new Promise(t=>this.then(e=>t([e,null])).catch(e=>t([null,e])))},...n}}),typeof Promise.withResolvers>"u"&&l(Promise,{withResolvers:{value:function(){let t=null,e=null;return{promise:new this((u,i)=>{t=u,e=i}),resolve:t,reject:e}},...n}}),l(Promise,{channel:{value:function(){let t=null,e=null;return[new this((u,i)=>{t=u,e=i}),t,e]},...n}}),l(JSON,{parse0:{value:function(t,e=null){try{if(typeof t!="string")throw new Error("not string");return JSON.parse(t)}catch{return e}},...n}})});
1
+ (function(l){typeof define=="function"&&define.amd?define(l):l()})(function(){"use strict";const l=Object.defineProperties,n={enumerable:!1,configurable:!0,writable:!0};function p(t={array:!1}){return function(e={},...r){const u=(i,s)=>{const o=Object.prototype.toString.call(i),f=Object.prototype.toString.call(s);if(o!==f)return s;if(o==="[object Array]")return t.array?i.concat(...s):s;if(o==="[object Object]"){for(const c in s)i[c]=u(i[c],s[c]);return i}else return s};for(const i of r)e=u(e,i);return e}}const b=p({array:!1}),d=p({array:!0});l(Object,{isObject:{value:function(t){return Object.prototype.toString.call(t)==="[object Object]"},...n},merge0:{value:function(...t){return b(this,...t)},...n},concat0:{value:function(...t){return d(this,...t)},...n}}),l(Object.prototype,{clone0:{value:function(){return JSON.parse(JSON.stringify(this))},...n},length0:{value:function(){return Object.keys(this).length},...n},entries0:{value:function(){return Object.entries(this)},...n},keys0:{value:function(){return Object.keys(this)},...n},values0:{value:function(){return Object.values(this)},...n},merge0:{value:function(...t){return b(this,...t)},...n},concat0:{value:function(...t){return d(this,...t)},...n},map0:{value:function(t=(r,u,i)=>[r,u],e=0){return Object.entries(this).map(([r,u])=>t(r,u,e++))},...n},pick0:{value:function(...t){const e={};for(const r of t)e[r]=this[r];return e},...n},omit0:{value:function(...t){const e={},r=new Set(t);for(const u in this)r.has(u)||(e[u]=this[u]);return e},...n},attr0:{value:function(t,...e){return typeof this!="object"?this:typeof t=="function"?t(this,...e):this[t]},...n},log0:{value:function(...t){return console.log(...t,this),this},...n},debug0:{value:function(...t){return console.debug(...t,this),this},...n},getParents0:{value:function(t=!1,e=-1,r="parent"){const u=t?[this]:[];let i=this[r];for(;i&&e--!=0;)u.push(i),i=i[r];return u},...n},getChildrens0:{value:function(t=!1,e=-1,r="children"){const u=[],i=(s,o,f)=>{if(o&&u.push(s),!(f==0||!s[r]||s[r].length==0))for(const c of s[r])i(c,!0,f-1)};return i(this,t,e),u},...n},treeFind0:{value:function(t,e=!0,r=-1,u="children"){if(e&&t(this))return this;if(r==0||!this[u]||this[u].length==0)return null;for(const i of this[u]){const s=i.treeFind0(t,!0,r-1,u);if(s!==null)return s}return null},...n},treeEach0:{value:function(t,e=!0,r=-1,u="children"){if(e&&t(this),!(r==0||!this[u]||this[u].length==0)){for(const i of this[u])i.treeEach0(t,!0,r-1,u);return this}},...n},treeMap0:{value:function(t,e=!0,r=-1,u="children",i=null){const s=e?t(this):this,o=[];if(r==0||!this[u]||this[u].length==0)return s;for(const f of this[u])o.push(f.treeMap0(t,!0,r-1,u,i));return s[u]=o,s},...n}}),l(Number.prototype,{ceil:{value:function(){return Math.ceil(this)},...n},floor:{value:function(){return Math.floor(this)},...n},round:{value:function(t=0){return t==0?Math.round(this):Math.round(this*10**t)/10**t},...n},trunc:{value:function(){return Math.trunc(this)},...n},abs:{value:function(){return Math.abs(this)},...n},max:{value:function(...t){return Math.max(this,...t)},...n},min:{value:function(...t){return Math.min(this,...t)},...n},baseConvert:{value:function(t=64){let e="",r=this,u="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";for(;r>0;)e=u.at(r%t)+e,r=Math.floor(r/t);return e||"0"},...n},toFixed0:{value:function(...t){return+this.toFixed(...t)},...n},toDate:{value:function(){return Date.new(this)},...n}}),l(BigInt.prototype,{toJSON:{value:function(){return this<BigInt(Number.MIN_SAFE_INTEGER)||this>BigInt(Number.MAX_SAFE_INTEGER)?this.toString():Number(this)},...n}}),l(String.prototype,{length0:{value:function(){return this.length},...n},substring0:{value:function(t=0,e=this.length){return t=t>=0?t:this.length+t,e=e>=0?e:this.length+e,this.substring(t,e)},...n},substr0:{value:function(t=0,e=this.length){return t=t>=0?t:this.length+t,e=t+e,this.substring(t,e)},...n},split0:{value:function(t=",",e=-1){const r=this?this.split(t):[];return e===-1?r:r.push0(r.splice(e-1).join(t))},...n},splitNumber:{value:function(t=","){return this.split0(t).map(e=>+e)},...n},splitSegment:{value:function(t=1){const e=[];for(let r=0;r<this.length;r+=t)e.push(this.substring(r,t));return e},...n},sprintf:{value:function(...t){let[e,...r]=this.split(/%[sd]/);for(let u=0;u<r.length;u++)e+=t[u]+r[u];return e},...n},subOf:{value:function(t,e,r=0,u=0){for(let o=0;o<r&&u!=-1;o++,u++)u=this.indexOf(t,u);let i=this.indexOf(t,u),s=this.indexOf(e,i);return i==-1||s==-1?"":(i+=t.length,this.substring(i,s))},...n},lastSubOf:{value:function(t,e,r=0,u=1/0){for(let o=0;o<r&&u!=-1;o++,u--)u=this.lastIndexOf(t,u);let i=this.lastIndexOf(t,u),s=this.indexOf(e,i);return i==-1||s==-1?"":(i+=t.length,this.substring(i,s))},...n},camel2under:{value:function(){return this.substr(0,1).toLowerCase()+this.substr(1).replace(/([A-Z])/g,(t,e)=>"_"+e.toLowerCase())},...n},under2camel:{value:function(){return this.replace(/_([a-z])/g,(t,e)=>e.toUpperCase())},...n},camel2pascal:{value:function(){return this.substr(0,1).toUpperCase()+this.substr(1)},...n},pascal2camel:{value:function(){return this.substr(0,1).toLowerCase()+this.substr(1)},...n},under2kebab:{value:function(){return this.replace(/_/g,"-")},...n},kebab2under:{value:function(){return this.replace(/-/g,"_")},...n},baseConvert:{value:function(t=64){let e=0,r="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";for(let u=0;u<this.length;u++)e=e*t+r.indexOf(this.at(u));return e},...n},toFixed0:{value:function(...t){return+(+this).toFixed(...t)},...n},toDate:{value:function(){return Date.new(this)},...n},hex2bytes:{value:function(){const t=[];for(let e=0;e<this.length;e+=2)t.push(Number.parseInt(this.substring(e,e+2),16));return t},...n},string2bytes:{value:function(){if(typeof TextEncoder<"u")return Array.from(new TextEncoder().encode(this));const t=[],e=encodeURIComponent(this);for(let r=0;r<e.length;)t.push(e.charAt(r)=="%"?Number.parseInt(e.substring(r+1,r+=3),16):e.charCodeAt(r++));return t},...n},base64decode:{value:function(t){const e=[],r={},u=t===!0?"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let s=0;s<u.length;s++)r[u.charAt(s)]=s;const i=this.charAt(this.length-1)!="="?this.length:this.charAt(this.length-2)!="="?this.length-1:this.length-2;for(let s=3;s<i;s+=4){const o=(r[this.charAt(s-3)]<<18)+(r[this.charAt(s-2)]<<12)+(r[this.charAt(s-1)]<<6)+r[this.charAt(s)];e.push((o&16711680)>>16,(o&65280)>>8,o&255)}if(i%4==3){const s=(r[this.charAt(i-3)]<<18)+(r[this.charAt(i-2)]<<12)+(r[this.charAt(i-1)]<<6);e.push((s&16711680)>>16,(s&65280)>>8)}else if(i%4==2){const s=(r[this.charAt(i-2)]<<18)+(r[this.charAt(i-1)]<<12);e.push((s&16711680)>>16)}return e},...n}}),typeof Iterator<"u"&&l(Iterator.prototype,{toArray:{value:function(){return Array.from(this)},...n}}),l(Array.prototype,{length0:{value:function(){return this.length},...n},entries0:{value:function(){return this.entries()},...n},push0:{value:function(...t){return this.push(...t),this},...n},push1:{value:function(...t){return this.push(...t),t[0]},...n},push3:{value:function(...t){return this.push(...t),t},...n},pop0:{value:function(...t){return this.pop(...t),this},...n},pop1:{value:function(...t){return this.pop(...t),t[0]},...n},pop3:{value:function(...t){return this.pop(...t),t},...n},unshift0:{value:function(...t){return this.unshift(...t),this},...n},unshift1:{value:function(...t){return this.unshift(...t),t[0]},...n},unshift3:{value:function(...t){return this.unshift(...t),t},...n},shift0:{value:function(...t){return this.shift(...t),this},...n},shift1:{value:function(...t){return this.shift(...t),t[0]},...n},shift3:{value:function(...t){return this.shift(...t),t},...n},first0:{value:function(t=null){return this.length?this[0]:t},...n},last0:{value:function(t=null){return this.length?this[this.length-1]:t},...n},find0:{value:function(t,e=null){return this.find(t)??e},...n},equals0:{value:function(t){return this.length===t.length&&(this===t||this.length===0||this.every((e,r)=>e===t[r]))},...n},unique0:{value:function(t=e=>e){const e=new Set;return this.filter(r=>e.has(t(r))?!1:!!e.add(t(r)))},...n},each0:{value:function(t){return this.forEach(t),this},...n},toObject:{value:function(t=(e,r)=>[r,e]){return Object.fromEntries(this.map(t))},...n},toMap:{value:function(t=(e,r)=>[r,e]){return new Map(this.map(t))},...n},toSet:{value:function(){return new Set(this)},...n},toGroup:{value:function(t=e=>[e.id,e]){const e={};for(const r of this){const[u,i]=t(r);u in e||(e[u]=[]),e[u].push(i)}return e},...n},toMerge:{value:function(t=u=>u.id,e=u=>({...u,children:u.children||[]}),r=(u,i)=>u.children.push(i)){const u=[];for(const i of this)r(u.find(s=>t(s)==t(i))??u.push1(e(i)),i);return u},...n},bytes2hex:{value:function(){let t="";for(let e=0;e<this.length;e++)t+=(this[e]<16?"0":"")+this[e].toString(16);return t},...n},bytes2string:{value:function(){if(typeof TextDecoder<"u")return new TextDecoder().decode(new Uint8Array(this));let t="";for(let e=0;e<this.length;e++)t+="%"+(this[e]<16?"0":"")+this[e].toString(16);return decodeURIComponent(t)},...n},base64encode:{value:function(t=!1,e=!0){let r="",u=t===!0?"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let i=2;i<this.length;i+=3){const s=(this[i-2]<<16)+(this[i-1]<<8)+this[i];r+=u.charAt((s&16515072)>>18)+u.charAt((s&258048)>>12)+u.charAt((s&4032)>>6)+u.charAt(s&63)}if(this.length%3==2){const i=(this[this.length-2]<<16)+(this[this.length-1]<<8);r+=u.charAt((i&16515072)>>18)+u.charAt((i&258048)>>12)+u.charAt((i&4032)>>6)+(e===!1?"":"=")}else if(this.length%3==1){const i=this[this.length-1]<<16;r+=u.charAt((i&16515072)>>18)+u.charAt((i&258048)>>12)+(e===!1?"":"==")}return r},...n},toUint8Array:{value:function(){return new Uint8Array(this)},...n},assoc:{value:function(t,e,r={}){const u=this.unique0(s=>s[t]),i=u.length==0?{}:typeof r=="function"?r(u):r;return this.each0(s=>s[e]=i[s[t]]??null)},...n},toTree:{value:function(t={}){const{id:e="id",pid:r="pid",level:u="level",root:i="root",parent:s="parent",children:o="children",empty:f=null,hasRoot:c=!0}=t,v=this.toObject(h=>[h[e],h]),g=this.toGroup(h=>[h[r],h]),a=this.length&&c?this.find(h=>h[r]===0):{[e]:0,[r]:-1,[i]:null,[s]:null,[o]:g[0]};l(a,{[i]:{value:a,enumerable:!1,configurable:!0,writable:!0}});for(const h of this)l(h,{[i]:{value:a,enumerable:!1,configurable:!0,writable:!0},[s]:{value:v[h[r]],enumerable:!1,configurable:!0,writable:!0}}),h[o]=g[h[e]]||f;return a.treeEach0(h=>h[u]=h[s]?h[s][u]+1:0,-1,o),a},...n},tree2tree:{value:function(t={},e=null,r=null){var g;const{id:u="id",pid:i="pid",level:s="level",root:o="root",parent:f="parent",children:c="children",empty:v=null}=t;e=e||{[u]:0,[i]:-1,[s]:0,[o]:null,[f]:null,[c]:this},r=r||e;for(const a of this)l(a,{[o]:{value:e,enumerable:!1,configurable:!0,writable:!0},[f]:{value:r,enumerable:!1,configurable:!0,writable:!0}}),a[i]=r[u],a[s]=r[s]+1,a[c]=a[c]&&a[c].length?a[c]:v,(g=a[c])==null||g.tree2tree(t,e,a);return e},...n},treeFind0:{value:function(t,e=!0,r=-1,u="children"){for(const i of this){const s=i.treeFind0(t,e,r,u);if(s!==null)return s}return null},...n},treeEach0:{value:function(t,e=!0,r=-1,u="children"){for(const i of this)i.treeEach0(t,e,r,u);return this},...n},treeMap0:{value:function(t,e=!0,r=-1,u="children",i=null){return this.map(s=>s.treeMap0(t,e,r,u,i))},...n}}),l(ArrayBuffer.prototype,{toUint8Array:{value:function(){return new Uint8Array(this)},...n}}),l(Uint8Array.prototype,{bytes2hex:{value:Array.prototype.bytes2hex,...n},bytes2string:{value:Array.prototype.bytes2string,...n},base64encode:{value:Array.prototype.base64encode,...n},toArray:{value:function(){return new Array(...this)},...n}}),l(Map.prototype,{length0:{value:function(){return this.size},...n},entries0:{value:function(){return[...this.entries()]},...n},keys0:{value:function(){return[...this.keys()]},...n},values0:{value:function(){return[...this.values()]},...n},get0:{value:function(t,e=null,...r){if(this.has(t))return this.get(t);const u=typeof e!="function"?e:e(t,...r);return this.set(t,u),u},...n},get1:{value:async function(t,e=null,...r){if(this.has(t))return this.get(t);const u=typeof e!="function"?e:await e(t,...r);return this.set(t,u),u},...n},toObject:{value:function(){return Object.fromEntries(this)},...n},toJSON:{value:function(){return[...this]},...n}}),l(Set.prototype,{length0:{value:function(){return this.size},...n},entries0:{value:function(){return this.entries()},...n},toArray:{value:function(){return[...this]},...n},toJSON:{value:function(){return[...this]},...n}}),l(Date,{new:{value:function(...t){return t.length!=1?new Date(...t):Number.isNaN(+t[0])?new Date(t[0].includes("T")?t[0]:t[0].replace(/-/g,"/")):new Date(t[0]>25e8?t[0]:t[0]*1e3)},...n},format:{value:function(t="y-m-d h:i:s"){return new Date().format(t)},...n},unix:{value:function(){return this.now()/1e3|0},...n},fromUnix:{value:function(t=0){return this.new((t||0)*1e3)},...n},expr:{value:function(t={}){return new Date().expr(t)},...n},toDayRange:{value:function(){const t=new Date,e=t.getFullYear(),r=t.getMonth(),u=t.getDate(),i=new Date(e,r,u).getTime()/1e3|0;return[i,i+86400-1]},...n},toWeekRange:{value:function(){let t=new Date;for(;t.getDay()!=1;)t=new Date(t.getTime()-86400);const e=t.getFullYear(),r=t.getMonth(),u=t.getDate(),i=new Date(e,r,u).getTime()/1e3|0;return[i,i+86400*7-1]},...n},toMonthRange:{value:function(){const t=new Date,e=t.getFullYear(),r=t.getMonth(),u=new Date(e,r,1).getTime()/1e3|0,i=new Date(e,r+1,0,23,59,59).getTime()/1e3|0;return[u,i]},...n},toYearRange:{value:function(){const e=new Date().getFullYear(),r=new Date(e,1,1).getTime()/1e3|0,u=new Date(e+1,1,0,23,59,59).getTime()/1e3|0;return[r,u]},...n}}),l(Date.prototype,{format:{value:function(t="y-m-d h:i:s"){if(this.getTime()===0)return"-";const e={y:this.getFullYear(),m:this.getMonth()+1,d:this.getDate(),h:this.getHours(),i:this.getMinutes(),s:this.getSeconds(),l:this.getMilliseconds(),e:this.getMonthDay()};return t.replace(/([ymdhisle])/ig,(r,u)=>u>="A"&&u<="Z"?e[u.toLowerCase()]:e[u].toString().padStart(u==="l"?3:2,"0"))},...n},unix:{value:function(){return this.getTime()/1e3|0},...n},isLeapYear:{value:function(){return this.getFullYear()%4===0&&this.getFullYear()%400!==0},...n},getMonthDay:{value:function(){return[31,0,31,30,31,30,31,31,30,31,30,31][this.getMonth()]||(this.isLeapYear()?29:28)},...n},expr:{value:function({y:t=0,m:e=0,d:r=0,h:u=0,i=0,s=0}){const o=new Date(this.getFullYear()+t,this.getMonth()+e+1,0);return new Date(this.getFullYear()+t,this.getMonth()+e,Math.min(o.getDate(),this.getDate())+r,this.getHours()+u,this.getMinutes()+i,this.getSeconds()+s)},...n},begin:{value:function(t=3){return new Date(...[this.getFullYear(),this.getMonth(),this.getDate(),this.getHours(),this.getMinutes(),this.getSeconds()].slice(0,t),...[this.getFullYear(),0,1,0,0,0].slice(t))},...n},end:{value:function(t=3){return new Date(...[this.getFullYear(),this.getMonth(),this.getDate(),this.getHours(),this.getMinutes(),this.getSeconds()].slice(0,t),...[this.getFullYear(),11,t<2?31:this.getMonthDay(),23,59,59].slice(t))},...n},week:{value:function(t,e=1){let r=new Date(this.getTime());for(;r.getDay()!==t;)r=new Date(r.getTime()+864e5*e);return r},...n},toJSON:{value:function(){return this.getTime()},...n}}),l(RegExp.prototype,{toJSON:{value:function(){return this.toString()},...n}}),l(Promise.prototype,{tryCatch:{value:function(){return new Promise(t=>this.then(e=>t([e,null])).catch(e=>t([null,e])))},...n}}),typeof Promise.withResolvers>"u"&&l(Promise,{withResolvers:{value:function(){let t=null,e=null;return{promise:new this((u,i)=>{t=u,e=i}),resolve:t,reject:e}},...n}}),l(Promise,{channel:{value:function(){let t=null,e=null;return[new this((u,i)=>{t=u,e=i}),t,e]},...n}}),l(JSON,{parse0:{value:function(t,e=null){try{if(typeof t!="string")throw new Error("not string");return JSON.parse(t)}catch{return e}},...n}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esexts",
3
- "version": "1.2.8",
3
+ "version": "1.3.0",
4
4
  "description": "esexts",
5
5
  "author": "dotcoo <dotcoo@163.com> (http://blog.dotcoo.com)",
6
6
  "homepage": "https://github.com/dotcoo/esexts#readme",
@@ -19,18 +19,12 @@
19
19
  "main": "dist/esexts.umd.cjs",
20
20
  "module": "dist/esexts.js",
21
21
  "exports": {
22
- ".": {
23
22
  "import": "dist/esexts.js",
24
23
  "require": "dist/esexts.umd.cjs"
25
24
  },
26
- "./es2018": {
27
- "import": "dist/esexts.es2018.js",
28
- "require": "dist/esexts.es2018.umd.cjs"
29
- }
30
- },
31
25
  "scripts": {
32
26
  "dev": "vite",
33
- "build": "vite build && vite build --mode=es2018 --emptyOutDir=false",
27
+ "build": "vite build",
34
28
  "preview": "vite preview"
35
29
  },
36
30
  "devDependencies": {
@@ -1,1002 +0,0 @@
1
- const l = Object.defineProperties, r = { enumerable: !1, configurable: !0, writable: !0 };
2
- function p(t = { array: !1 }) {
3
- return function(e = {}, ...n) {
4
- const u = (i, s) => {
5
- const o = Object.prototype.toString.call(i), f = Object.prototype.toString.call(s);
6
- if (o !== f)
7
- return s;
8
- if (o === "[object Array]")
9
- return t.array ? i.concat(...s) : s;
10
- if (o === "[object Object]") {
11
- for (const c in s)
12
- i[c] = u(i[c], s[c]);
13
- return i;
14
- } else
15
- return s;
16
- };
17
- for (const i of n)
18
- e = u(e, i);
19
- return e;
20
- };
21
- }
22
- const b = p({ array: !1 }), d = p({ array: !0 });
23
- l(Object, {
24
- isObject: {
25
- value: function(t) {
26
- return Object.prototype.toString.call(t) === "[object Object]";
27
- },
28
- ...r
29
- },
30
- merge0: {
31
- value: function(...t) {
32
- return b(this, ...t);
33
- },
34
- ...r
35
- },
36
- concat0: {
37
- value: function(...t) {
38
- return d(this, ...t);
39
- },
40
- ...r
41
- }
42
- });
43
- l(Object.prototype, {
44
- clone0: {
45
- value: function() {
46
- return JSON.parse(JSON.stringify(this));
47
- },
48
- ...r
49
- },
50
- length0: {
51
- value: function() {
52
- return Object.keys(this).length;
53
- },
54
- ...r
55
- },
56
- entries0: {
57
- value: function() {
58
- return Object.entries(this);
59
- },
60
- ...r
61
- },
62
- keys0: {
63
- value: function() {
64
- return Object.keys(this);
65
- },
66
- ...r
67
- },
68
- values0: {
69
- value: function() {
70
- return Object.values(this);
71
- },
72
- ...r
73
- },
74
- merge0: {
75
- value: function(...t) {
76
- return b(this, ...t);
77
- },
78
- ...r
79
- },
80
- concat0: {
81
- value: function(...t) {
82
- return d(this, ...t);
83
- },
84
- ...r
85
- },
86
- map0: {
87
- value: function(t = (n, u, i) => [n, u], e = 0) {
88
- return Object.entries(this).map(([n, u]) => t(n, u, e++));
89
- },
90
- ...r
91
- },
92
- pick0: {
93
- value: function(...t) {
94
- const e = {};
95
- for (const n of t)
96
- e[n] = this[n];
97
- return e;
98
- },
99
- ...r
100
- },
101
- omit0: {
102
- value: function(...t) {
103
- const e = {}, n = new Set(t);
104
- for (const u in this)
105
- n.has(u) || (e[u] = this[u]);
106
- return e;
107
- },
108
- ...r
109
- },
110
- attr0: {
111
- value: function(t, ...e) {
112
- return typeof this != "object" ? this : typeof t == "function" ? t(this, ...e) : this[t];
113
- },
114
- ...r
115
- },
116
- log0: {
117
- value: function(...t) {
118
- return console.log(...t, this), this;
119
- },
120
- ...r
121
- },
122
- debug0: {
123
- value: function(...t) {
124
- return console.debug(...t, this), this;
125
- },
126
- ...r
127
- },
128
- // ====== Tree ======
129
- getParents0: {
130
- value: function(t = !1, e = -1, n = "parent") {
131
- const u = t ? [this] : [];
132
- let i = this[n];
133
- for (; i && e-- != 0; )
134
- u.push(i), i = i[n];
135
- return u;
136
- },
137
- ...r
138
- },
139
- getChildrens0: {
140
- value: function(t = !1, e = -1, n = "children") {
141
- const u = [], i = (s, o, f) => {
142
- if (o && u.push(s), !(f == 0 || !s[n] || s[n].length == 0))
143
- for (const c of s[n])
144
- i(c, !0, f - 1);
145
- };
146
- return i(this, t, e), u;
147
- },
148
- ...r
149
- },
150
- treeFind0: {
151
- value: function(t, e = !0, n = -1, u = "children") {
152
- if (e && t(this))
153
- return this;
154
- if (n == 0 || !this[u] || this[u].length == 0)
155
- return null;
156
- for (const i of this[u]) {
157
- const s = i.treeFind0(t, !0, n - 1, u);
158
- if (s !== null)
159
- return s;
160
- }
161
- return null;
162
- },
163
- ...r
164
- },
165
- treeEach0: {
166
- value: function(t, e = !0, n = -1, u = "children") {
167
- if (e && t(this), !(n == 0 || !this[u] || this[u].length == 0)) {
168
- for (const i of this[u])
169
- i.treeEach0(t, !0, n - 1, u);
170
- return this;
171
- }
172
- },
173
- ...r
174
- },
175
- treeMap0: {
176
- value: function(t, e = !0, n = -1, u = "children", i = null) {
177
- const s = e ? t(this) : this, o = [];
178
- if (n == 0 || !this[u] || this[u].length == 0)
179
- return s;
180
- for (const f of this[u])
181
- o.push(f.treeMap0(t, !0, n - 1, u, i));
182
- return s[u] = o, s;
183
- },
184
- ...r
185
- }
186
- });
187
- l(Number.prototype, {
188
- ceil: {
189
- value: function() {
190
- return Math.ceil(this);
191
- },
192
- ...r
193
- },
194
- floor: {
195
- value: function() {
196
- return Math.floor(this);
197
- },
198
- ...r
199
- },
200
- round: {
201
- value: function(t = 0) {
202
- return t == 0 ? Math.round(this) : Math.round(this * 10 ** t) / 10 ** t;
203
- },
204
- ...r
205
- },
206
- trunc: {
207
- value: function() {
208
- return Math.trunc(this);
209
- },
210
- ...r
211
- },
212
- abs: {
213
- value: function() {
214
- return Math.abs(this);
215
- },
216
- ...r
217
- },
218
- max: {
219
- value: function(...t) {
220
- return Math.max(this, ...t);
221
- },
222
- ...r
223
- },
224
- min: {
225
- value: function(...t) {
226
- return Math.min(this, ...t);
227
- },
228
- ...r
229
- },
230
- baseConvert: {
231
- value: function(t = 64) {
232
- let e = "", n = this, u = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
233
- for (; n > 0; )
234
- e = u.at(n % t) + e, n = Math.floor(n / t);
235
- return e || "0";
236
- },
237
- ...r
238
- },
239
- toFixed0: {
240
- value: function(...t) {
241
- return +this.toFixed(...t);
242
- },
243
- ...r
244
- },
245
- toDate: {
246
- value: function() {
247
- return Date.new(this);
248
- },
249
- ...r
250
- }
251
- });
252
- l(BigInt.prototype, {
253
- toJSON: {
254
- value: function() {
255
- return this > /* @__PURE__ */ BigInt(9007199254740991) || this < -/* @__PURE__ */ BigInt(9007199254740991) ? this.toString() : Number(this);
256
- },
257
- ...r
258
- }
259
- });
260
- l(String.prototype, {
261
- length0: {
262
- value: function() {
263
- return this.length;
264
- },
265
- ...r
266
- },
267
- substring0: {
268
- value: function(t = 0, e = this.length) {
269
- return t = t >= 0 ? t : this.length + t, e = e >= 0 ? e : this.length + e, this.substring(t, e);
270
- },
271
- ...r
272
- },
273
- substr0: {
274
- value: function(t = 0, e = this.length) {
275
- return t = t >= 0 ? t : this.length + t, e = t + e, this.substring(t, e);
276
- },
277
- ...r
278
- },
279
- split0: {
280
- value: function(t = ",", e = -1) {
281
- const n = this ? this.split(t) : [];
282
- return e === -1 ? n : n.push0(n.splice(e - 1).join(t));
283
- },
284
- ...r
285
- },
286
- splitNumber: {
287
- value: function(t = ",") {
288
- return this.split0(t).map((e) => +e);
289
- },
290
- ...r
291
- },
292
- splitSegment: {
293
- value: function(t = 1) {
294
- const e = [];
295
- for (let n = 0; n < this.length; n += t)
296
- e.push(this.substring(n, t));
297
- return e;
298
- },
299
- ...r
300
- },
301
- sprintf: {
302
- value: function(...t) {
303
- let [e, ...n] = this.split(/%[sd]/);
304
- for (let u = 0; u < n.length; u++)
305
- e += t[u] + n[u];
306
- return e;
307
- },
308
- ...r
309
- },
310
- subOf: {
311
- value: function(t, e, n = 0, u = 0) {
312
- for (let o = 0; o < n && u != -1; o++, u++)
313
- u = this.indexOf(t, u);
314
- let i = this.indexOf(t, u), s = this.indexOf(e, i);
315
- return i == -1 || s == -1 ? "" : (i += t.length, this.substring(i, s));
316
- },
317
- ...r
318
- },
319
- lastSubOf: {
320
- value: function(t, e, n = 0, u = 1 / 0) {
321
- for (let o = 0; o < n && u != -1; o++, u--)
322
- u = this.lastIndexOf(t, u);
323
- let i = this.lastIndexOf(t, u), s = this.indexOf(e, i);
324
- return i == -1 || s == -1 ? "" : (i += t.length, this.substring(i, s));
325
- },
326
- ...r
327
- },
328
- camel2under: {
329
- value: function() {
330
- return this.substr(0, 1).toLowerCase() + this.substr(1).replace(/([A-Z])/g, (t, e) => "_" + e.toLowerCase());
331
- },
332
- ...r
333
- },
334
- under2camel: {
335
- value: function() {
336
- return this.replace(/_([a-z])/g, (t, e) => e.toUpperCase());
337
- },
338
- ...r
339
- },
340
- camel2pascal: {
341
- value: function() {
342
- return this.substr(0, 1).toUpperCase() + this.substr(1);
343
- },
344
- ...r
345
- },
346
- pascal2camel: {
347
- value: function() {
348
- return this.substr(0, 1).toLowerCase() + this.substr(1);
349
- },
350
- ...r
351
- },
352
- under2kebab: {
353
- value: function() {
354
- return this.replace(/_/g, "-");
355
- },
356
- ...r
357
- },
358
- kebab2under: {
359
- value: function() {
360
- return this.replace(/-/g, "_");
361
- },
362
- ...r
363
- },
364
- baseConvert: {
365
- value: function(t = 64) {
366
- let e = 0, n = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";
367
- for (let u = 0; u < this.length; u++)
368
- e = e * t + n.indexOf(this.at(u));
369
- return e;
370
- },
371
- ...r
372
- },
373
- toFixed0: {
374
- value: function(...t) {
375
- return +(+this).toFixed(...t);
376
- },
377
- ...r
378
- },
379
- toDate: {
380
- value: function() {
381
- return Date.new(this);
382
- },
383
- ...r
384
- },
385
- hex2bytes: {
386
- value: function() {
387
- const t = [];
388
- for (let e = 0; e < this.length; e += 2)
389
- t.push(Number.parseInt(this.substring(e, e + 2), 16));
390
- return t;
391
- },
392
- ...r
393
- },
394
- string2bytes: {
395
- value: function() {
396
- if (typeof TextEncoder != "undefined")
397
- return Array.from(new TextEncoder().encode(this));
398
- const t = [], e = encodeURIComponent(this);
399
- for (let n = 0; n < e.length; )
400
- t.push(e.charAt(n) == "%" ? Number.parseInt(e.substring(n + 1, n += 3), 16) : e.charCodeAt(n++));
401
- return t;
402
- },
403
- ...r
404
- },
405
- base64decode: {
406
- value: function(t) {
407
- const e = [], n = {}, u = t === !0 ? "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
408
- for (let s = 0; s < u.length; s++)
409
- n[u.charAt(s)] = s;
410
- const i = this.charAt(this.length - 1) != "=" ? this.length : this.charAt(this.length - 2) != "=" ? this.length - 1 : this.length - 2;
411
- for (let s = 3; s < i; s += 4) {
412
- const o = (n[this.charAt(s - 3)] << 18) + (n[this.charAt(s - 2)] << 12) + (n[this.charAt(s - 1)] << 6) + n[this.charAt(s)];
413
- e.push((o & 16711680) >> 16, (o & 65280) >> 8, o & 255);
414
- }
415
- if (i % 4 == 3) {
416
- const s = (n[this.charAt(i - 3)] << 18) + (n[this.charAt(i - 2)] << 12) + (n[this.charAt(i - 1)] << 6);
417
- e.push((s & 16711680) >> 16, (s & 65280) >> 8);
418
- } else if (i % 4 == 2) {
419
- const s = (n[this.charAt(i - 2)] << 18) + (n[this.charAt(i - 1)] << 12);
420
- e.push((s & 16711680) >> 16);
421
- }
422
- return e;
423
- },
424
- ...r
425
- }
426
- });
427
- typeof Iterator != "undefined" && l(Iterator.prototype, {
428
- toArray: {
429
- value: function() {
430
- return Array.from(this);
431
- },
432
- ...r
433
- }
434
- });
435
- l(Array.prototype, {
436
- length0: {
437
- value: function() {
438
- return this.length;
439
- },
440
- ...r
441
- },
442
- entries0: {
443
- value: function() {
444
- return this.entries();
445
- },
446
- ...r
447
- },
448
- push0: {
449
- value: function(...t) {
450
- return this.push(...t), this;
451
- },
452
- ...r
453
- },
454
- push1: {
455
- value: function(...t) {
456
- return this.push(...t), t[0];
457
- },
458
- ...r
459
- },
460
- push3: {
461
- value: function(...t) {
462
- return this.push(...t), t;
463
- },
464
- ...r
465
- },
466
- pop0: {
467
- value: function(...t) {
468
- return this.pop(...t), this;
469
- },
470
- ...r
471
- },
472
- pop1: {
473
- value: function(...t) {
474
- return this.pop(...t), t[0];
475
- },
476
- ...r
477
- },
478
- pop3: {
479
- value: function(...t) {
480
- return this.pop(...t), t;
481
- },
482
- ...r
483
- },
484
- unshift0: {
485
- value: function(...t) {
486
- return this.unshift(...t), this;
487
- },
488
- ...r
489
- },
490
- unshift1: {
491
- value: function(...t) {
492
- return this.unshift(...t), t[0];
493
- },
494
- ...r
495
- },
496
- unshift3: {
497
- value: function(...t) {
498
- return this.unshift(...t), t;
499
- },
500
- ...r
501
- },
502
- shift0: {
503
- value: function(...t) {
504
- return this.shift(...t), this;
505
- },
506
- ...r
507
- },
508
- shift1: {
509
- value: function(...t) {
510
- return this.shift(...t), t[0];
511
- },
512
- ...r
513
- },
514
- shift3: {
515
- value: function(...t) {
516
- return this.shift(...t), t;
517
- },
518
- ...r
519
- },
520
- first0: {
521
- value: function(t = null) {
522
- return this.length ? this[0] : t;
523
- },
524
- ...r
525
- },
526
- last0: {
527
- value: function(t = null) {
528
- return this.length ? this[this.length - 1] : t;
529
- },
530
- ...r
531
- },
532
- find0: {
533
- value: function(t, e = null) {
534
- var n;
535
- return (n = this.find(t)) != null ? n : e;
536
- },
537
- ...r
538
- },
539
- equals0: {
540
- value: function(t) {
541
- return this.length === t.length && (this === t || this.length === 0 || this.every((e, n) => e === t[n]));
542
- },
543
- ...r
544
- },
545
- unique0: {
546
- value: function(t = (e) => e) {
547
- const e = /* @__PURE__ */ new Set();
548
- return this.filter((n) => e.has(t(n)) ? !1 : !!e.add(t(n)));
549
- },
550
- ...r
551
- },
552
- each0: {
553
- value: function(t) {
554
- return this.forEach(t), this;
555
- },
556
- ...r
557
- },
558
- toObject: {
559
- value: function(t = (e, n) => [n, e]) {
560
- return Object.fromEntries(this.map(t));
561
- },
562
- ...r
563
- },
564
- toMap: {
565
- value: function(t = (e, n) => [n, e]) {
566
- return new Map(this.map(t));
567
- },
568
- ...r
569
- },
570
- toSet: {
571
- value: function() {
572
- return new Set(this);
573
- },
574
- ...r
575
- },
576
- toGroup: {
577
- value: function(t = (e) => [e.id, e]) {
578
- const e = {};
579
- for (const n of this) {
580
- const [u, i] = t(n);
581
- u in e || (e[u] = []), e[u].push(i);
582
- }
583
- return e;
584
- },
585
- ...r
586
- },
587
- toMerge: {
588
- value: function(t = (u) => u.id, e = (u) => ({ ...u, children: u.children || [] }), n = (u, i) => u.children.push(i)) {
589
- var i;
590
- const u = [];
591
- for (const s of this)
592
- n((i = u.find((o) => t(o) == t(s))) != null ? i : u.push1(e(s)), s);
593
- return u;
594
- },
595
- ...r
596
- },
597
- bytes2hex: {
598
- value: function() {
599
- let t = "";
600
- for (let e = 0; e < this.length; e++)
601
- t += (this[e] < 16 ? "0" : "") + this[e].toString(16);
602
- return t;
603
- },
604
- ...r
605
- },
606
- bytes2string: {
607
- value: function() {
608
- if (typeof TextDecoder != "undefined")
609
- return new TextDecoder().decode(new Uint8Array(this));
610
- let t = "";
611
- for (let e = 0; e < this.length; e++)
612
- t += "%" + (this[e] < 16 ? "0" : "") + this[e].toString(16);
613
- return decodeURIComponent(t);
614
- },
615
- ...r
616
- },
617
- base64encode: {
618
- value: function(t = !1, e = !0) {
619
- let n = "", u = t === !0 ? "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
620
- for (let i = 2; i < this.length; i += 3) {
621
- const s = (this[i - 2] << 16) + (this[i - 1] << 8) + this[i];
622
- n += u.charAt((s & 16515072) >> 18) + u.charAt((s & 258048) >> 12) + u.charAt((s & 4032) >> 6) + u.charAt(s & 63);
623
- }
624
- if (this.length % 3 == 2) {
625
- const i = (this[this.length - 2] << 16) + (this[this.length - 1] << 8);
626
- n += u.charAt((i & 16515072) >> 18) + u.charAt((i & 258048) >> 12) + u.charAt((i & 4032) >> 6) + (e === !1 ? "" : "=");
627
- } else if (this.length % 3 == 1) {
628
- const i = this[this.length - 1] << 16;
629
- n += u.charAt((i & 16515072) >> 18) + u.charAt((i & 258048) >> 12) + (e === !1 ? "" : "==");
630
- }
631
- return n;
632
- },
633
- ...r
634
- },
635
- toUint8Array: {
636
- value: function() {
637
- return new Uint8Array(this);
638
- },
639
- ...r
640
- },
641
- // ====== Relational ======
642
- assoc: {
643
- value: function(t, e, n = {}) {
644
- const u = this.unique0((s) => s[t]), i = u.length == 0 ? {} : typeof n == "function" ? n(u) : n;
645
- return this.each0((s) => {
646
- var o;
647
- return s[e] = (o = i[s[t]]) != null ? o : null;
648
- });
649
- },
650
- ...r
651
- },
652
- // ====== Tree ======
653
- toTree: {
654
- value: function(t = {}) {
655
- const { id: e = "id", pid: n = "pid", level: u = "level", root: i = "root", parent: s = "parent", children: o = "children", empty: f = null, hasRoot: c = !0 } = t, v = this.toObject((h) => [h[e], h]), g = this.toGroup((h) => [h[n], h]), a = this.length && c ? this.find((h) => h[n] === 0) : { [e]: 0, [n]: -1, [i]: null, [s]: null, [o]: g[0] };
656
- l(a, { [i]: { value: a, enumerable: !1, configurable: !0, writable: !0 } });
657
- for (const h of this)
658
- l(h, {
659
- [i]: { value: a, enumerable: !1, configurable: !0, writable: !0 },
660
- [s]: { value: v[h[n]], enumerable: !1, configurable: !0, writable: !0 }
661
- }), h[o] = g[h[e]] || f;
662
- return a.treeEach0((h) => h[u] = h[s] ? h[s][u] + 1 : 0, -1, o), a;
663
- },
664
- ...r
665
- },
666
- tree2tree: {
667
- value: function(t = {}, e = null, n = null) {
668
- var g;
669
- const { id: u = "id", pid: i = "pid", level: s = "level", root: o = "root", parent: f = "parent", children: c = "children", empty: v = null } = t;
670
- e = e || { [u]: 0, [i]: -1, [s]: 0, [o]: null, [f]: null, [c]: this }, n = n || e;
671
- for (const a of this)
672
- l(a, {
673
- [o]: { value: e, enumerable: !1, configurable: !0, writable: !0 },
674
- [f]: { value: n, enumerable: !1, configurable: !0, writable: !0 }
675
- }), a[i] = n[u], a[s] = n[s] + 1, a[c] = a[c] && a[c].length ? a[c] : v, (g = a[c]) == null || g.tree2tree(t, e, a);
676
- return e;
677
- },
678
- ...r
679
- },
680
- treeFind0: {
681
- value: function(t, e = !0, n = -1, u = "children") {
682
- for (const i of this) {
683
- const s = i.treeFind0(t, e, n, u);
684
- if (s !== null)
685
- return s;
686
- }
687
- return null;
688
- },
689
- ...r
690
- },
691
- treeEach0: {
692
- value: function(t, e = !0, n = -1, u = "children") {
693
- for (const i of this)
694
- i.treeEach0(t, e, n, u);
695
- return this;
696
- },
697
- ...r
698
- },
699
- treeMap0: {
700
- value: function(t, e = !0, n = -1, u = "children", i = null) {
701
- return this.map((s) => s.treeMap0(t, e, n, u, i));
702
- },
703
- ...r
704
- }
705
- });
706
- l(ArrayBuffer.prototype, {
707
- toUint8Array: {
708
- value: function() {
709
- return new Uint8Array(this);
710
- },
711
- ...r
712
- }
713
- });
714
- l(Uint8Array.prototype, {
715
- bytes2hex: {
716
- value: Array.prototype.bytes2hex,
717
- ...r
718
- },
719
- bytes2string: {
720
- value: Array.prototype.bytes2string,
721
- ...r
722
- },
723
- base64encode: {
724
- value: Array.prototype.base64encode,
725
- ...r
726
- },
727
- toArray: {
728
- value: function() {
729
- return new Array(...this);
730
- },
731
- ...r
732
- }
733
- });
734
- l(Map.prototype, {
735
- length0: {
736
- value: function() {
737
- return this.size;
738
- },
739
- ...r
740
- },
741
- entries0: {
742
- value: function() {
743
- return [...this.entries()];
744
- },
745
- ...r
746
- },
747
- keys0: {
748
- value: function() {
749
- return [...this.keys()];
750
- },
751
- ...r
752
- },
753
- values0: {
754
- value: function() {
755
- return [...this.values()];
756
- },
757
- ...r
758
- },
759
- get0: {
760
- value: function(t, e = null, ...n) {
761
- if (this.has(t))
762
- return this.get(t);
763
- const u = typeof e != "function" ? e : e(t, ...n);
764
- return this.set(t, u), u;
765
- },
766
- ...r
767
- },
768
- get1: {
769
- value: async function(t, e = null, ...n) {
770
- if (this.has(t))
771
- return this.get(t);
772
- const u = typeof e != "function" ? e : await e(t, ...n);
773
- return this.set(t, u), u;
774
- },
775
- ...r
776
- },
777
- toObject: {
778
- value: function() {
779
- return Object.fromEntries(this);
780
- },
781
- ...r
782
- },
783
- toJSON: {
784
- value: function() {
785
- return [...this];
786
- },
787
- ...r
788
- }
789
- });
790
- l(Set.prototype, {
791
- length0: {
792
- value: function() {
793
- return this.size;
794
- },
795
- ...r
796
- },
797
- entries0: {
798
- value: function() {
799
- return this.entries();
800
- },
801
- ...r
802
- },
803
- toArray: {
804
- value: function() {
805
- return [...this];
806
- },
807
- ...r
808
- },
809
- toJSON: {
810
- value: function() {
811
- return [...this];
812
- },
813
- ...r
814
- }
815
- });
816
- l(Date, {
817
- new: {
818
- value: function(...t) {
819
- return t.length != 1 ? new Date(...t) : Number.isNaN(+t[0]) ? new Date(t[0].includes("T") ? t[0] : t[0].replace(/-/g, "/")) : new Date(t[0] > 25e8 ? t[0] : t[0] * 1e3);
820
- },
821
- ...r
822
- },
823
- format: {
824
- value: function(t = "y-m-d h:i:s") {
825
- return (/* @__PURE__ */ new Date()).format(t);
826
- },
827
- ...r
828
- },
829
- unix: {
830
- value: function() {
831
- return this.now() / 1e3 | 0;
832
- },
833
- ...r
834
- },
835
- fromUnix: {
836
- value: function(t = 0) {
837
- return this.new((t || 0) * 1e3);
838
- },
839
- ...r
840
- },
841
- expr: {
842
- value: function(t = {}) {
843
- return (/* @__PURE__ */ new Date()).expr(t);
844
- },
845
- ...r
846
- },
847
- toDayRange: {
848
- value: function() {
849
- const t = /* @__PURE__ */ new Date(), e = t.getFullYear(), n = t.getMonth(), u = t.getDate(), i = new Date(e, n, u).getTime() / 1e3 | 0;
850
- return [i, i + 86400 - 1];
851
- },
852
- ...r
853
- },
854
- toWeekRange: {
855
- value: function() {
856
- let t = /* @__PURE__ */ new Date();
857
- for (; t.getDay() != 1; )
858
- t = new Date(t.getTime() - 86400);
859
- const e = t.getFullYear(), n = t.getMonth(), u = t.getDate(), i = new Date(e, n, u).getTime() / 1e3 | 0;
860
- return [i, i + 86400 * 7 - 1];
861
- },
862
- ...r
863
- },
864
- toMonthRange: {
865
- value: function() {
866
- const t = /* @__PURE__ */ new Date(), e = t.getFullYear(), n = t.getMonth(), u = new Date(e, n, 1).getTime() / 1e3 | 0, i = new Date(e, n + 1, 0, 23, 59, 59).getTime() / 1e3 | 0;
867
- return [u, i];
868
- },
869
- ...r
870
- },
871
- toYearRange: {
872
- value: function() {
873
- const e = (/* @__PURE__ */ new Date()).getFullYear(), n = new Date(e, 1, 1).getTime() / 1e3 | 0, u = new Date(e + 1, 1, 0, 23, 59, 59).getTime() / 1e3 | 0;
874
- return [n, u];
875
- },
876
- ...r
877
- }
878
- });
879
- l(Date.prototype, {
880
- format: {
881
- value: function(t = "y-m-d h:i:s") {
882
- if (this.getTime() === 0)
883
- return "-";
884
- const e = {
885
- y: this.getFullYear(),
886
- m: this.getMonth() + 1,
887
- d: this.getDate(),
888
- h: this.getHours(),
889
- i: this.getMinutes(),
890
- s: this.getSeconds(),
891
- l: this.getMilliseconds(),
892
- e: this.getMonthDay()
893
- };
894
- return t.replace(/([ymdhisle])/ig, (n, u) => u >= "A" && u <= "Z" ? e[u.toLowerCase()] : e[u].toString().padStart(u === "l" ? 3 : 2, "0"));
895
- },
896
- ...r
897
- },
898
- unix: {
899
- value: function() {
900
- return this.getTime() / 1e3 | 0;
901
- },
902
- ...r
903
- },
904
- isLeapYear: {
905
- value: function() {
906
- return this.getFullYear() % 4 === 0 && this.getFullYear() % 400 !== 0;
907
- },
908
- ...r
909
- },
910
- getMonthDay: {
911
- value: function() {
912
- return [31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][this.getMonth()] || (this.isLeapYear() ? 29 : 28);
913
- },
914
- ...r
915
- },
916
- expr: {
917
- value: function({ y: t = 0, m: e = 0, d: n = 0, h: u = 0, i = 0, s = 0 }) {
918
- const o = new Date(this.getFullYear() + t, this.getMonth() + e + 1, 0);
919
- return new Date(this.getFullYear() + t, this.getMonth() + e, Math.min(o.getDate(), this.getDate()) + n, this.getHours() + u, this.getMinutes() + i, this.getSeconds() + s);
920
- },
921
- ...r
922
- },
923
- begin: {
924
- value: function(t = 3) {
925
- return new Date(...[this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()].slice(0, t), ...[this.getFullYear(), 0, 1, 0, 0, 0].slice(t));
926
- },
927
- ...r
928
- },
929
- end: {
930
- value: function(t = 3) {
931
- return new Date(...[this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()].slice(0, t), ...[this.getFullYear(), 11, t < 2 ? 31 : this.getMonthDay(), 23, 59, 59].slice(t));
932
- },
933
- ...r
934
- },
935
- week: {
936
- value: function(t, e = 1) {
937
- let n = new Date(this.getTime());
938
- for (; n.getDay() !== t; )
939
- n = new Date(n.getTime() + 864e5 * e);
940
- return n;
941
- },
942
- ...r
943
- },
944
- toJSON: {
945
- value: function() {
946
- return this.getTime();
947
- },
948
- ...r
949
- }
950
- });
951
- l(RegExp.prototype, {
952
- toJSON: {
953
- value: function() {
954
- return this.toString();
955
- },
956
- ...r
957
- }
958
- });
959
- l(Promise.prototype, {
960
- tryCatch: {
961
- value: function() {
962
- return new Promise((t) => this.then((e) => t([e, null])).catch((e) => t([null, e])));
963
- },
964
- ...r
965
- }
966
- });
967
- typeof Promise.withResolvers == "undefined" && l(Promise, {
968
- withResolvers: {
969
- value: function() {
970
- let t = null, e = null;
971
- return { promise: new this((u, i) => {
972
- t = u, e = i;
973
- }), resolve: t, reject: e };
974
- },
975
- ...r
976
- }
977
- });
978
- l(Promise, {
979
- channel: {
980
- value: function() {
981
- let t = null, e = null;
982
- return [new this((u, i) => {
983
- t = u, e = i;
984
- }), t, e];
985
- },
986
- ...r
987
- }
988
- });
989
- l(JSON, {
990
- parse0: {
991
- value: function(t, e = null) {
992
- try {
993
- if (typeof t != "string")
994
- throw new Error("not string");
995
- return JSON.parse(t);
996
- } catch (n) {
997
- return e;
998
- }
999
- },
1000
- ...r
1001
- }
1002
- });
@@ -1 +0,0 @@
1
- (function(l){typeof define=="function"&&define.amd?define(l):l()})(function(){"use strict";const l=Object.defineProperties,r={enumerable:!1,configurable:!0,writable:!0};function p(t={array:!1}){return function(e={},...n){const u=(i,s)=>{const o=Object.prototype.toString.call(i),f=Object.prototype.toString.call(s);if(o!==f)return s;if(o==="[object Array]")return t.array?i.concat(...s):s;if(o==="[object Object]"){for(const c in s)i[c]=u(i[c],s[c]);return i}else return s};for(const i of n)e=u(e,i);return e}}const d=p({array:!1}),b=p({array:!0});l(Object,{isObject:{value:function(t){return Object.prototype.toString.call(t)==="[object Object]"},...r},merge0:{value:function(...t){return d(this,...t)},...r},concat0:{value:function(...t){return b(this,...t)},...r}}),l(Object.prototype,{clone0:{value:function(){return JSON.parse(JSON.stringify(this))},...r},length0:{value:function(){return Object.keys(this).length},...r},entries0:{value:function(){return Object.entries(this)},...r},keys0:{value:function(){return Object.keys(this)},...r},values0:{value:function(){return Object.values(this)},...r},merge0:{value:function(...t){return d(this,...t)},...r},concat0:{value:function(...t){return b(this,...t)},...r},map0:{value:function(t=(n,u,i)=>[n,u],e=0){return Object.entries(this).map(([n,u])=>t(n,u,e++))},...r},pick0:{value:function(...t){const e={};for(const n of t)e[n]=this[n];return e},...r},omit0:{value:function(...t){const e={},n=new Set(t);for(const u in this)n.has(u)||(e[u]=this[u]);return e},...r},attr0:{value:function(t,...e){return typeof this!="object"?this:typeof t=="function"?t(this,...e):this[t]},...r},log0:{value:function(...t){return console.log(...t,this),this},...r},debug0:{value:function(...t){return console.debug(...t,this),this},...r},getParents0:{value:function(t=!1,e=-1,n="parent"){const u=t?[this]:[];let i=this[n];for(;i&&e--!=0;)u.push(i),i=i[n];return u},...r},getChildrens0:{value:function(t=!1,e=-1,n="children"){const u=[],i=(s,o,f)=>{if(o&&u.push(s),!(f==0||!s[n]||s[n].length==0))for(const c of s[n])i(c,!0,f-1)};return i(this,t,e),u},...r},treeFind0:{value:function(t,e=!0,n=-1,u="children"){if(e&&t(this))return this;if(n==0||!this[u]||this[u].length==0)return null;for(const i of this[u]){const s=i.treeFind0(t,!0,n-1,u);if(s!==null)return s}return null},...r},treeEach0:{value:function(t,e=!0,n=-1,u="children"){if(e&&t(this),!(n==0||!this[u]||this[u].length==0)){for(const i of this[u])i.treeEach0(t,!0,n-1,u);return this}},...r},treeMap0:{value:function(t,e=!0,n=-1,u="children",i=null){const s=e?t(this):this,o=[];if(n==0||!this[u]||this[u].length==0)return s;for(const f of this[u])o.push(f.treeMap0(t,!0,n-1,u,i));return s[u]=o,s},...r}}),l(Number.prototype,{ceil:{value:function(){return Math.ceil(this)},...r},floor:{value:function(){return Math.floor(this)},...r},round:{value:function(t=0){return t==0?Math.round(this):Math.round(this*10**t)/10**t},...r},trunc:{value:function(){return Math.trunc(this)},...r},abs:{value:function(){return Math.abs(this)},...r},max:{value:function(...t){return Math.max(this,...t)},...r},min:{value:function(...t){return Math.min(this,...t)},...r},baseConvert:{value:function(t=64){let e="",n=this,u="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";for(;n>0;)e=u.at(n%t)+e,n=Math.floor(n/t);return e||"0"},...r},toFixed0:{value:function(...t){return+this.toFixed(...t)},...r},toDate:{value:function(){return Date.new(this)},...r}}),l(BigInt.prototype,{toJSON:{value:function(){return this>BigInt(9007199254740991)||this<-BigInt(9007199254740991)?this.toString():Number(this)},...r}}),l(String.prototype,{length0:{value:function(){return this.length},...r},substring0:{value:function(t=0,e=this.length){return t=t>=0?t:this.length+t,e=e>=0?e:this.length+e,this.substring(t,e)},...r},substr0:{value:function(t=0,e=this.length){return t=t>=0?t:this.length+t,e=t+e,this.substring(t,e)},...r},split0:{value:function(t=",",e=-1){const n=this?this.split(t):[];return e===-1?n:n.push0(n.splice(e-1).join(t))},...r},splitNumber:{value:function(t=","){return this.split0(t).map(e=>+e)},...r},splitSegment:{value:function(t=1){const e=[];for(let n=0;n<this.length;n+=t)e.push(this.substring(n,t));return e},...r},sprintf:{value:function(...t){let[e,...n]=this.split(/%[sd]/);for(let u=0;u<n.length;u++)e+=t[u]+n[u];return e},...r},subOf:{value:function(t,e,n=0,u=0){for(let o=0;o<n&&u!=-1;o++,u++)u=this.indexOf(t,u);let i=this.indexOf(t,u),s=this.indexOf(e,i);return i==-1||s==-1?"":(i+=t.length,this.substring(i,s))},...r},lastSubOf:{value:function(t,e,n=0,u=1/0){for(let o=0;o<n&&u!=-1;o++,u--)u=this.lastIndexOf(t,u);let i=this.lastIndexOf(t,u),s=this.indexOf(e,i);return i==-1||s==-1?"":(i+=t.length,this.substring(i,s))},...r},camel2under:{value:function(){return this.substr(0,1).toLowerCase()+this.substr(1).replace(/([A-Z])/g,(t,e)=>"_"+e.toLowerCase())},...r},under2camel:{value:function(){return this.replace(/_([a-z])/g,(t,e)=>e.toUpperCase())},...r},camel2pascal:{value:function(){return this.substr(0,1).toUpperCase()+this.substr(1)},...r},pascal2camel:{value:function(){return this.substr(0,1).toLowerCase()+this.substr(1)},...r},under2kebab:{value:function(){return this.replace(/_/g,"-")},...r},kebab2under:{value:function(){return this.replace(/-/g,"_")},...r},baseConvert:{value:function(t=64){let e=0,n="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";for(let u=0;u<this.length;u++)e=e*t+n.indexOf(this.at(u));return e},...r},toFixed0:{value:function(...t){return+(+this).toFixed(...t)},...r},toDate:{value:function(){return Date.new(this)},...r},hex2bytes:{value:function(){const t=[];for(let e=0;e<this.length;e+=2)t.push(Number.parseInt(this.substring(e,e+2),16));return t},...r},string2bytes:{value:function(){if(typeof TextEncoder!="undefined")return Array.from(new TextEncoder().encode(this));const t=[],e=encodeURIComponent(this);for(let n=0;n<e.length;)t.push(e.charAt(n)=="%"?Number.parseInt(e.substring(n+1,n+=3),16):e.charCodeAt(n++));return t},...r},base64decode:{value:function(t){const e=[],n={},u=t===!0?"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let s=0;s<u.length;s++)n[u.charAt(s)]=s;const i=this.charAt(this.length-1)!="="?this.length:this.charAt(this.length-2)!="="?this.length-1:this.length-2;for(let s=3;s<i;s+=4){const o=(n[this.charAt(s-3)]<<18)+(n[this.charAt(s-2)]<<12)+(n[this.charAt(s-1)]<<6)+n[this.charAt(s)];e.push((o&16711680)>>16,(o&65280)>>8,o&255)}if(i%4==3){const s=(n[this.charAt(i-3)]<<18)+(n[this.charAt(i-2)]<<12)+(n[this.charAt(i-1)]<<6);e.push((s&16711680)>>16,(s&65280)>>8)}else if(i%4==2){const s=(n[this.charAt(i-2)]<<18)+(n[this.charAt(i-1)]<<12);e.push((s&16711680)>>16)}return e},...r}}),typeof Iterator!="undefined"&&l(Iterator.prototype,{toArray:{value:function(){return Array.from(this)},...r}}),l(Array.prototype,{length0:{value:function(){return this.length},...r},entries0:{value:function(){return this.entries()},...r},push0:{value:function(...t){return this.push(...t),this},...r},push1:{value:function(...t){return this.push(...t),t[0]},...r},push3:{value:function(...t){return this.push(...t),t},...r},pop0:{value:function(...t){return this.pop(...t),this},...r},pop1:{value:function(...t){return this.pop(...t),t[0]},...r},pop3:{value:function(...t){return this.pop(...t),t},...r},unshift0:{value:function(...t){return this.unshift(...t),this},...r},unshift1:{value:function(...t){return this.unshift(...t),t[0]},...r},unshift3:{value:function(...t){return this.unshift(...t),t},...r},shift0:{value:function(...t){return this.shift(...t),this},...r},shift1:{value:function(...t){return this.shift(...t),t[0]},...r},shift3:{value:function(...t){return this.shift(...t),t},...r},first0:{value:function(t=null){return this.length?this[0]:t},...r},last0:{value:function(t=null){return this.length?this[this.length-1]:t},...r},find0:{value:function(t,e=null){var n;return(n=this.find(t))!=null?n:e},...r},equals0:{value:function(t){return this.length===t.length&&(this===t||this.length===0||this.every((e,n)=>e===t[n]))},...r},unique0:{value:function(t=e=>e){const e=new Set;return this.filter(n=>e.has(t(n))?!1:!!e.add(t(n)))},...r},each0:{value:function(t){return this.forEach(t),this},...r},toObject:{value:function(t=(e,n)=>[n,e]){return Object.fromEntries(this.map(t))},...r},toMap:{value:function(t=(e,n)=>[n,e]){return new Map(this.map(t))},...r},toSet:{value:function(){return new Set(this)},...r},toGroup:{value:function(t=e=>[e.id,e]){const e={};for(const n of this){const[u,i]=t(n);u in e||(e[u]=[]),e[u].push(i)}return e},...r},toMerge:{value:function(t=u=>u.id,e=u=>({...u,children:u.children||[]}),n=(u,i)=>u.children.push(i)){var i;const u=[];for(const s of this)n((i=u.find(o=>t(o)==t(s)))!=null?i:u.push1(e(s)),s);return u},...r},bytes2hex:{value:function(){let t="";for(let e=0;e<this.length;e++)t+=(this[e]<16?"0":"")+this[e].toString(16);return t},...r},bytes2string:{value:function(){if(typeof TextDecoder!="undefined")return new TextDecoder().decode(new Uint8Array(this));let t="";for(let e=0;e<this.length;e++)t+="%"+(this[e]<16?"0":"")+this[e].toString(16);return decodeURIComponent(t)},...r},base64encode:{value:function(t=!1,e=!0){let n="",u=t===!0?"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let i=2;i<this.length;i+=3){const s=(this[i-2]<<16)+(this[i-1]<<8)+this[i];n+=u.charAt((s&16515072)>>18)+u.charAt((s&258048)>>12)+u.charAt((s&4032)>>6)+u.charAt(s&63)}if(this.length%3==2){const i=(this[this.length-2]<<16)+(this[this.length-1]<<8);n+=u.charAt((i&16515072)>>18)+u.charAt((i&258048)>>12)+u.charAt((i&4032)>>6)+(e===!1?"":"=")}else if(this.length%3==1){const i=this[this.length-1]<<16;n+=u.charAt((i&16515072)>>18)+u.charAt((i&258048)>>12)+(e===!1?"":"==")}return n},...r},toUint8Array:{value:function(){return new Uint8Array(this)},...r},assoc:{value:function(t,e,n={}){const u=this.unique0(s=>s[t]),i=u.length==0?{}:typeof n=="function"?n(u):n;return this.each0(s=>{var o;return s[e]=(o=i[s[t]])!=null?o:null})},...r},toTree:{value:function(t={}){const{id:e="id",pid:n="pid",level:u="level",root:i="root",parent:s="parent",children:o="children",empty:f=null,hasRoot:c=!0}=t,v=this.toObject(h=>[h[e],h]),g=this.toGroup(h=>[h[n],h]),a=this.length&&c?this.find(h=>h[n]===0):{[e]:0,[n]:-1,[i]:null,[s]:null,[o]:g[0]};l(a,{[i]:{value:a,enumerable:!1,configurable:!0,writable:!0}});for(const h of this)l(h,{[i]:{value:a,enumerable:!1,configurable:!0,writable:!0},[s]:{value:v[h[n]],enumerable:!1,configurable:!0,writable:!0}}),h[o]=g[h[e]]||f;return a.treeEach0(h=>h[u]=h[s]?h[s][u]+1:0,-1,o),a},...r},tree2tree:{value:function(t={},e=null,n=null){var g;const{id:u="id",pid:i="pid",level:s="level",root:o="root",parent:f="parent",children:c="children",empty:v=null}=t;e=e||{[u]:0,[i]:-1,[s]:0,[o]:null,[f]:null,[c]:this},n=n||e;for(const a of this)l(a,{[o]:{value:e,enumerable:!1,configurable:!0,writable:!0},[f]:{value:n,enumerable:!1,configurable:!0,writable:!0}}),a[i]=n[u],a[s]=n[s]+1,a[c]=a[c]&&a[c].length?a[c]:v,(g=a[c])==null||g.tree2tree(t,e,a);return e},...r},treeFind0:{value:function(t,e=!0,n=-1,u="children"){for(const i of this){const s=i.treeFind0(t,e,n,u);if(s!==null)return s}return null},...r},treeEach0:{value:function(t,e=!0,n=-1,u="children"){for(const i of this)i.treeEach0(t,e,n,u);return this},...r},treeMap0:{value:function(t,e=!0,n=-1,u="children",i=null){return this.map(s=>s.treeMap0(t,e,n,u,i))},...r}}),l(ArrayBuffer.prototype,{toUint8Array:{value:function(){return new Uint8Array(this)},...r}}),l(Uint8Array.prototype,{bytes2hex:{value:Array.prototype.bytes2hex,...r},bytes2string:{value:Array.prototype.bytes2string,...r},base64encode:{value:Array.prototype.base64encode,...r},toArray:{value:function(){return new Array(...this)},...r}}),l(Map.prototype,{length0:{value:function(){return this.size},...r},entries0:{value:function(){return[...this.entries()]},...r},keys0:{value:function(){return[...this.keys()]},...r},values0:{value:function(){return[...this.values()]},...r},get0:{value:function(t,e=null,...n){if(this.has(t))return this.get(t);const u=typeof e!="function"?e:e(t,...n);return this.set(t,u),u},...r},get1:{value:async function(t,e=null,...n){if(this.has(t))return this.get(t);const u=typeof e!="function"?e:await e(t,...n);return this.set(t,u),u},...r},toObject:{value:function(){return Object.fromEntries(this)},...r},toJSON:{value:function(){return[...this]},...r}}),l(Set.prototype,{length0:{value:function(){return this.size},...r},entries0:{value:function(){return this.entries()},...r},toArray:{value:function(){return[...this]},...r},toJSON:{value:function(){return[...this]},...r}}),l(Date,{new:{value:function(...t){return t.length!=1?new Date(...t):Number.isNaN(+t[0])?new Date(t[0].includes("T")?t[0]:t[0].replace(/-/g,"/")):new Date(t[0]>25e8?t[0]:t[0]*1e3)},...r},format:{value:function(t="y-m-d h:i:s"){return new Date().format(t)},...r},unix:{value:function(){return this.now()/1e3|0},...r},fromUnix:{value:function(t=0){return this.new((t||0)*1e3)},...r},expr:{value:function(t={}){return new Date().expr(t)},...r},toDayRange:{value:function(){const t=new Date,e=t.getFullYear(),n=t.getMonth(),u=t.getDate(),i=new Date(e,n,u).getTime()/1e3|0;return[i,i+86400-1]},...r},toWeekRange:{value:function(){let t=new Date;for(;t.getDay()!=1;)t=new Date(t.getTime()-86400);const e=t.getFullYear(),n=t.getMonth(),u=t.getDate(),i=new Date(e,n,u).getTime()/1e3|0;return[i,i+86400*7-1]},...r},toMonthRange:{value:function(){const t=new Date,e=t.getFullYear(),n=t.getMonth(),u=new Date(e,n,1).getTime()/1e3|0,i=new Date(e,n+1,0,23,59,59).getTime()/1e3|0;return[u,i]},...r},toYearRange:{value:function(){const e=new Date().getFullYear(),n=new Date(e,1,1).getTime()/1e3|0,u=new Date(e+1,1,0,23,59,59).getTime()/1e3|0;return[n,u]},...r}}),l(Date.prototype,{format:{value:function(t="y-m-d h:i:s"){if(this.getTime()===0)return"-";const e={y:this.getFullYear(),m:this.getMonth()+1,d:this.getDate(),h:this.getHours(),i:this.getMinutes(),s:this.getSeconds(),l:this.getMilliseconds(),e:this.getMonthDay()};return t.replace(/([ymdhisle])/ig,(n,u)=>u>="A"&&u<="Z"?e[u.toLowerCase()]:e[u].toString().padStart(u==="l"?3:2,"0"))},...r},unix:{value:function(){return this.getTime()/1e3|0},...r},isLeapYear:{value:function(){return this.getFullYear()%4===0&&this.getFullYear()%400!==0},...r},getMonthDay:{value:function(){return[31,0,31,30,31,30,31,31,30,31,30,31][this.getMonth()]||(this.isLeapYear()?29:28)},...r},expr:{value:function({y:t=0,m:e=0,d:n=0,h:u=0,i=0,s=0}){const o=new Date(this.getFullYear()+t,this.getMonth()+e+1,0);return new Date(this.getFullYear()+t,this.getMonth()+e,Math.min(o.getDate(),this.getDate())+n,this.getHours()+u,this.getMinutes()+i,this.getSeconds()+s)},...r},begin:{value:function(t=3){return new Date(...[this.getFullYear(),this.getMonth(),this.getDate(),this.getHours(),this.getMinutes(),this.getSeconds()].slice(0,t),...[this.getFullYear(),0,1,0,0,0].slice(t))},...r},end:{value:function(t=3){return new Date(...[this.getFullYear(),this.getMonth(),this.getDate(),this.getHours(),this.getMinutes(),this.getSeconds()].slice(0,t),...[this.getFullYear(),11,t<2?31:this.getMonthDay(),23,59,59].slice(t))},...r},week:{value:function(t,e=1){let n=new Date(this.getTime());for(;n.getDay()!==t;)n=new Date(n.getTime()+864e5*e);return n},...r},toJSON:{value:function(){return this.getTime()},...r}}),l(RegExp.prototype,{toJSON:{value:function(){return this.toString()},...r}}),l(Promise.prototype,{tryCatch:{value:function(){return new Promise(t=>this.then(e=>t([e,null])).catch(e=>t([null,e])))},...r}}),typeof Promise.withResolvers=="undefined"&&l(Promise,{withResolvers:{value:function(){let t=null,e=null;return{promise:new this((u,i)=>{t=u,e=i}),resolve:t,reject:e}},...r}}),l(Promise,{channel:{value:function(){let t=null,e=null;return[new this((u,i)=>{t=u,e=i}),t,e]},...r}}),l(JSON,{parse0:{value:function(t,e=null){try{if(typeof t!="string")throw new Error("not string");return JSON.parse(t)}catch(n){return e}},...r}})});