esexts 1.2.5 → 1.2.7
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.es2018.js +1002 -0
- package/dist/esexts.es2018.umd.cjs +1 -0
- package/dist/esexts.js +442 -700
- package/dist/esexts.umd.cjs +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
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}})});
|