@wxhccc/es-util 2.1.2 → 2.1.3

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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.1.2
3
- * (c) 2023 wxhccc
2
+ * @wxhccc/es-util v2.1.3
3
+ * (c) 2026 wxhccc
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.1.2
3
- * (c) 2023 wxhccc
2
+ * @wxhccc/es-util v2.1.3
3
+ * (c) 2026 wxhccc
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.1.2
3
- * (c) 2023 wxhccc
2
+ * @wxhccc/es-util v2.1.3
3
+ * (c) 2026 wxhccc
4
4
  * @license MIT
5
5
  */
6
6
  const { hasOwnProperty, toString } = Object.prototype;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.1.2
3
- * (c) 2023 wxhccc
2
+ * @wxhccc/es-util v2.1.3
3
+ * (c) 2026 wxhccc
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
package/dist/index.min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.1.2
3
- * (c) 2023 wxhccc
2
+ * @wxhccc/es-util v2.1.3
3
+ * (c) 2026 wxhccc
4
4
  * @license MIT
5
5
  */
6
6
  !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).EsUtil={})}(this,(function(e){"use strict";const{hasOwnProperty:t,toString:n}=Object.prototype,r=(e,t)=>{Object.keys(e).forEach(((n,r)=>t(n,e[n],r)))},s=e=>"function"==typeof e,i=Array.isArray,o=e=>{const t=(r=e,n.call(r)).match(/^\[object (.*)\]$/);var r;return t?t[1]:""},a=e=>"Object"===o(e),c=(e,n)=>t.call(e,n);function l(e,t=[]){return{[e]:t}}const d=/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;const u={telphone:{startCharIndex:-8,endCharIndex:-5},idcard:{startCharIndex:-12,endCharIndex:-5}};async function f(e){try{return[null,await e]}catch(e){return[e,void 0]}}const p=function(e,t){const{wrap:n,lock:r,syncRefHandle:o}={...t};let a,c,l=!1,d=!1;const u=e=>{if(c){const[t,n]=c;t[n]=e}a&&a(e)};if(r){const e=e=>i(e)&&2===e.length;e(r)?c=r:s(r)&&(a=r,e(o)&&(c=o)),l=!(!a&&!c),l&&(d=!!c&&!!c[0][c[1]])}let p;if(s(e)){const t=d?Promise.resolve(void 0):e();p=n?f(t):t}else p=n?f(e):e;return p instanceof Promise&&l&&!d&&(u(!0),p.finally((()=>u(!1)))),p};function m(e="",t){try{return JSON.parse(e)}catch(e){return t}}const h=e=>""===e||null==e,y=(e,t)=>{const n={};return r(e,((e,r)=>{h(r)||(t?i(r)?n[e]=r.map((e=>a(e)?y(e):e)):n[e]=a(r)?y(r):r:n[e]=r)})),n},g=e=>{if(null!==e){if(i(e))return e.map(g);if(a(e)){const t={};return r(e,((e,n)=>{t[e]=g(n)})),t}return e}},b=(e,t,n)=>{const o=Object.keys(t),a={},c={};r(e,(t=>{o.includes(t)?a[t]=e[t]:c[t]=e[t]}));const l=Object.keys(a);if(0===l.length)return e;const{filterNullable:d,dateFormat:u}={filterNullable:!0,...n},f=l.reduce(((e,n)=>{const r=a[n],o=t[n];if(!r||!o)return e;if("join"===o||"pop"===o)i(r)&&r.length&&(e[n]="join"===o?r.join(","):r.slice(-1)[0]);else if(2===o.length||3===o.length){if(!r||2!==r.length)return e;const[t,n,i]=o,[a,c]=r;Object.assign(e,{[t]:s(u)?u(a,i):a,[n]:s(u)?u(c,i):c})}return e}),{}),p={...c,...f};return d?y(p):p},M=e=>"string"==typeof e,j=Symbol("NOMETHOD");function x(e){const t=new Map([[j,new Set]]),{name:n,customHanlderCreator:r}=e||{},i=s(r)?r(t):null,o=/\|-[a-z]+-\|/,a=(e,...t)=>{try{e(...t)}catch(e){console.error(e)}},c=s(i)?i:e=>{const{method:r,data:s,originEmitterName:i,targetEmitterName:c}=e||[];if(r&&"string"==typeof r){const e=[];t.forEach(((t,n)=>{if("string"==typeof n&&n.startsWith(r)){const[,r]=n.split(o);r&&i&&r!==i||e.push(...t)}})),!e.length||n&&c&&n!==c||e.forEach((e=>a(e,s)))}const l=t.get(j);l&&l.forEach((t=>a(t,s,e)))},l=(e,t)=>{const{limitFrom:n="",namespace:r=""}=t||{};return(n||r)&&"string"==typeof e?`${e}|-from-|${n}|-ns-|${r}`:e},d=(e,t,r)=>M(e)?{method:e,data:t,...r&&M(r)?{targetEmitterName:r}:{},...n&&M(n)?{originEmitterName:n}:{}}:e;return{name:n,rootEventListener:c,on:(e,n,r)=>{if("symbol"==typeof e&&e!==j)return;const s=l(e,r);t.has(s)||t.set(s,new Set);const i=t.get(s);i?.add(n)},off:(e,n,r)=>{if("symbol"==typeof e&&e!==j)return;const{namespace:s}=r||{};if(s&&!e)return void t.forEach(((e,n)=>{"string"==typeof n&&n.endsWith(s)&&t.delete(n)}));const i=l(e,r);n?t.get(i)?.delete(n):t.delete(i)},emit:(...e)=>{const t=d(...e);c(t)},createPayload:d,removeAllListeners:()=>{t.clear()},getMethodNames:e=>{if(!e){const e=[];return t.forEach(((t,n)=>M(n)&&e.push(n.split(o)))),e}const n=[];return t.forEach(((e,t)=>M(t)&&n.push(t))),n},getListeners:(e,n)=>{if("symbol"==typeof e)return e===j?Array.from(t.get(j)||[]):[];const r=l(e,n),s=t.get(r);return s?Array.from(s):[]}}}e.ChinaIdCardValid=function(e){const t=e.toString().toUpperCase();return d.test(t)&&["11","12","13","14","15","21","22","23","31","32","33","34","35","36","37","41","42","43","44","45","46","50","51","52","53","54","61","62","63","64","65","71","81","82","91"].includes(t.substr(0,2))&&(()=>{if(18===t.length){const e=t.split(""),n=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2],r=[1,0,"X",9,8,7,6,5,4,3,2];let s=0,i=0,o=0;for(let t=0;t<17;t++)i=parseInt(e[t]),o=n[t],s+=i*o;return r[s%11].toString()===e[17]}return!0})()},e.NOMETHOD=j,e.array2tree=function(e,t={}){const{primaryKey:n,parentKey:r,childrenKey:o,createRoot:a,parentRefKey:d}={primaryKey:"id",parentKey:"pid",childrenKey:"children",createRoot:!1,parentRefKey:!1,...t},u=d&&("string"==typeof d?d:"_parent"),f={},p=[];if(i(e)){const t=[],s=e=>{e.forEach((e=>{c(f,e[n])||(f[e[n]]={...e,...l(o)}),e[r]?c(f,e[r])?f[e[r]][o].push(Object.assign(f[e[n]],u?{[u]:f[e[r]]}:{})):t.push(e):p.push(f[e[n]])}))};s(e),t.length&&s(t)}return s(a)?a(p):a?{[o]:p}:p},e.awaitWrapper=f,e.b64UriDecode=e=>decodeURIComponent(window.atob(e)),e.b64UriEncode=e=>window.btoa(encodeURIComponent(e)),e.byteStringify=function(e,t){const n=Object.assign({standard:"jedec",unitLvl:"auto",precision:1,detail:!1},t),{standard:r,unitLvl:s,precision:o,detail:a}=n;let c=parseFloat(e);if(!Number.isFinite(c))return;const l=c<0?-1:1;c=Math.abs(c);const{base:d,unitMap:u}=((e,t)=>{const n={B:{expMax:0,units:{metric:"B",iec:"B",jedec:"B"}},K:{expMax:1,units:{metric:"kB",iec:"KiB",jedec:"KB"}},M:{expMax:2,units:{metric:"MB",iec:"MiB",jedec:"MB"}},G:{expMax:3,units:{metric:"GB",iec:"GiB",jedec:"GB"}},T:{expMax:4,units:{metric:"TB",iec:"TiB",jedec:"TB"}},P:{expMax:5,units:{metric:"PB",iec:"PiB",jedec:"PB"}},E:{expMax:6,units:{metric:"EB",iec:"EiB",jedec:"EB"}},Z:{expMax:7,units:{metric:"ZB",iec:"ZiB",jedec:"ZB"}},Y:{expMax:8,units:{metric:"YB",iec:"YiB",jedec:"YB"}}},r={metric:1e3,iec:1024,jedec:1024};return{base:r[e]||r.jedec,unitMap:n[t]||Object.values(n)}})(r,s),f=e=>Number.isInteger(e)?e:e.toFixed(o);let p="",m=0;if(i(u))u.some((e=>{const t=Math.pow(d,e.expMax),n=c/t;return!(n>d)&&(p=e.units[r],m=f(n*l),!0)}));else{const e=Math.pow(d,u.expMax);p=u.units[r];m=f(c/e*l)}return a?{value:m,unit:p}:`${m} ${p}`},e.checkoutBy=function(e,t,n){return a(e)?i(t)?t.map((t=>e[t])):t&&a(t)?Object.keys(t).map((r=>{const s=t[r];return a(e[r])&&a(s)?n?n({},e[r],s):Object.assign({},e[r],s):s||e[r]})):Object.values(e):[]},e.createRAFTimer=e=>{const{autoStopWhenNoTask:t,autoStartWhenAddTask:n}={...e};let r=0,s=!0,i=0,o=0,a=[],c=!1;const l=e=>{const n=e-(o||e);o=e,i+=n,c&&(a=a.filter((e=>!e.needClear)),c=!1),!t||a.length?(a.forEach((e=>{const{callback:t,maxTime:r,runTime:s,elapsed:o,interval:a,needClear:l}=e;if(!l){if(r&&s>=r)return e.needClear=!0,void(c=!0);if(o>=a){try{t(i)}catch(e){}e.elapsed=0,e.runTime+=1}else e.elapsed+=n}})),r=window.requestAnimationFrame(l)):s=!0},d=()=>{r=window.requestAnimationFrame(l),s=!1},u=()=>{window.cancelAnimationFrame(r),s=!0};return{start:d,stop:u,pauseToggle:()=>{s?d():u()},addTask:(e,t,r)=>{e&&(n&&s&&d(),a.push({callback:e,elapsed:0,interval:t,maxTime:r,runTime:0}))},removeTask:e=>{a=a.filter((t=>t.callback!==e))},isPaused:()=>s}},e.eventTargetEmitter=x,e.filterNullable=y,e.formParamsSwitch=b,e.formParamsSwitchCreator=e=>(t,n,r)=>b(t,n,{dateFormat:e,...r}),e.formulaValidate=function(e,t){return e=e.replace(/\s/g,""),!/[+\-*/]{2,}/.test(e)&&!/\(\)/.test(e)&&!/\([+\-*/]/.test(e)&&!/[+\-*/]\)/.test(e)&&!/[^+\-*/]\(/.test(e)&&!/\)[^+\-*/]/.test(e)&&(()=>{const t=[];for(let n,r=0;r<e.length;r++)if(n=e.charAt(r),"("===n)t.push("(");else if(")"===n){if(!(t.length>0))return!1;t.pop()}return!t.length})()&&(!i(t)||(n=t,e.replace(/[()+\-*/]{1,}/g,"`").split("`").every((e=>!/[A-Z]/i.test(e)||n.includes(e)))));var n},e.isNullable=h,e.mapToObject=function(e,t="key",n="value"){const r={};return i(e)&&t&&n&&[t,n].every((e=>["string","function"].includes(typeof e)))&&e.forEach(((e,s)=>{const i="string"==typeof t?e[t]:t(e,s),o="string"==typeof n?e[n]:n(e,s);["string","number"].includes(typeof i)&&(r[i]=o)})),r},e.maskData=function(e,t){if("string"!=typeof e||!e)return"";const n=t&&t.mode&&u[t.mode]?u[t.mode]:{},{maskWith:r,startCharIndex:s=0,endCharIndex:i,startFrom:o,endUntil:a}={maskWith:"*",...n,...t};let c=e,l="",d="";const f=o?e.indexOf(o):-1;if(f>-1){const t=f+o.length;c=c.slice(t),l=e.slice(0,t)}const p=a?e.lastIndexOf(a):-1;p>-1&&(c=c.slice(0,p),d=e.slice(p));const m=c.split(""),h=[l],y=m.length,g=[s>=0?s:y+s,void 0!==i?i>=0?i:y+i:y-1];let[b,M]=g;return M=M>0&&M<y?M:y-1,b=b>=0&&b<=M?b:0,m.forEach(((e,t)=>{h.push(t>=b&&t<=M?r:e)})),h.push(d),h.join("")},e.pageCommunicate=function(e){const{messageHanlder:t,currentPage:n}=e||{},{emit:r,on:s,off:i,createPayload:o,removeAllListeners:a}=x({name:n,customHanlderCreator:t}),c=e=>r(e.data);let l;const d=window.localStorage,u="PAGE_COMMUNICATE_CHANNEL";if(void 0!==typeof window.BroadcastChannel)l=new BroadcastChannel(u),l.addEventListener("message",c);else{const e=()=>{const e=m(d.getItem(u)||"");e&&r(e)};window.addEventListener("storage",e)}return{on:s,off:i,send:(...e)=>{const t=o(...e);if(l)l.postMessage(t);else{const e=JSON.stringify({...t,ts:+new Date});d.setItem(u,e)}},destory:()=>{a(),l?l.close():d.removeItem(u)}}},e.pickRenameKeys=function(e,t){if(!(e&&a(e)&&t&&a(t)))return;const n={};for(const r in e)r in t&&(n[t[r]]=e[r]);return n},e.safeJsonParse=m,e.secondsToDuration=(e,t="h")=>{const n=Number.isInteger(e)?e:Math.round(e),r={s:n%60};switch(t){case"m":r.m=Math.floor(n/60);break;case"h":r.m=Math.floor(n%3600/60),r.h=Math.floor(n/3600);break;case"d":r.m=Math.floor(n%3600/60),r.h=Math.floor(n%86400/3600),r.d=Math.floor(n/3600/24)}return r},e.switchNullToUndefined=g,e.tree2array=function(e,t={}){const{primaryKey:n,parentKey:r,childrenKey:s,hasParentKey:o,returnObject:a}=Object.assign({hasParentKey:!0,primaryKey:"id",parentKey:"pid",childrenKey:"children",returnObject:!1},t),c=a?{}:[];return i(e)||"object"==typeof e?(function e(t,l,d=!1){const u=o?{}:{[r]:l};if(!d){const e=Object.assign(u,function(e,t){const n={};for(const r in e)r!==t&&(n[r]=e[r]);return n}(t,s));a?c[t[n]]=e:c.push(e)}i(t[s])&&t[s].length&&t[s].forEach((r=>e(r,t[n])))}(i(e)?l(s,e):e,null,!0),c):c},e.treeAnalyse=function(e,t,n){const r={nodes:[],childKeysMaps:{},keyNodeMap:{},disabledKeys:[]},s=Array.isArray(n)?n:["nodes","keyNodeMap","childKeysMaps","disabledKeys"],{primaryKey:i,labelKey:o,disabledKey:a,childrenKey:c}={primaryKey:"id",labelKey:"name",childrenKey:"children",disabledKey:"disabled",...t},[l,d,u,f]=Object.keys(r).map((e=>s.includes(e))),p=(e,t)=>{e.forEach((e=>{const{[i]:n,[o]:s,[c]:m,[a]:h}=e;let y;l&&r.nodes.push(e),u&&void 0!==n&&(y={keyVlaue:n,keyLabel:s,parent:t,children:[]},t?.children.push(y),r.keyNodeMap[n]=y),f&&h&&void 0!==n&&r.disabledKeys.push(n),Array.isArray(m)&&m.length&&(d&&(r.childKeysMaps[n]=m.map((e=>e[i]))),p(m,y))}))};return e&&p(e),r},e.wp=p,Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.1.2
3
- * (c) 2023 wxhccc
2
+ * @wxhccc/es-util v2.1.3
3
+ * (c) 2026 wxhccc
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
package/dist/optional.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.1.2
3
- * (c) 2023 wxhccc
2
+ * @wxhccc/es-util v2.1.3
3
+ * (c) 2026 wxhccc
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.1.2
3
- * (c) 2023 wxhccc
2
+ * @wxhccc/es-util v2.1.3
3
+ * (c) 2026 wxhccc
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
package/dist/promise.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.1.2
3
- * (c) 2023 wxhccc
2
+ * @wxhccc/es-util v2.1.3
3
+ * (c) 2026 wxhccc
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
package/dist/raf-timer.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.1.2
3
- * (c) 2023 wxhccc
2
+ * @wxhccc/es-util v2.1.3
3
+ * (c) 2026 wxhccc
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.1.2
3
- * (c) 2023 wxhccc
2
+ * @wxhccc/es-util v2.1.3
3
+ * (c) 2026 wxhccc
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
package/dist/validate.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.1.2
3
- * (c) 2023 wxhccc
2
+ * @wxhccc/es-util v2.1.3
3
+ * (c) 2026 wxhccc
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
@@ -0,0 +1 @@
1
+ export * from './value-string-switch/index';
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.1.2
3
- * (c) 2023 wxhccc
2
+ * @wxhccc/es-util v2.1.3
3
+ * (c) 2026 wxhccc
4
4
  * @license MIT
5
5
  */
6
6
  'use strict';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxhccc/es-util",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "A library that contains some useful methods",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",