@wxhccc/es-util 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2019 hjw
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2019 hjw
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.0.1
2
+ * @wxhccc/es-util v2.0.2
3
3
  * (c) 2022 wxhccc
4
4
  * @license MIT
5
5
  */
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.0.1
2
+ * @wxhccc/es-util v2.0.2
3
3
  * (c) 2022 wxhccc
4
4
  * @license MIT
5
5
  */
@@ -700,7 +700,7 @@ function pageCommunicate(options) {
700
700
  let bc;
701
701
  const ls = window.localStorage;
702
702
  const channelName = 'PAGE_COMMUNICATE_CHANNEL';
703
- if (typeof BroadcastChannel !== undefined) {
703
+ if (typeof window.BroadcastChannel !== undefined) {
704
704
  bc = new BroadcastChannel(channelName);
705
705
  bc.addEventListener('message', onMessage);
706
706
  }
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.0.1
2
+ * @wxhccc/es-util v2.0.2
3
3
  * (c) 2022 wxhccc
4
4
  * @license MIT
5
5
  */
@@ -704,7 +704,7 @@ function pageCommunicate(options) {
704
704
  let bc;
705
705
  const ls = window.localStorage;
706
706
  const channelName = 'PAGE_COMMUNICATE_CHANNEL';
707
- if (typeof BroadcastChannel !== undefined) {
707
+ if (typeof window.BroadcastChannel !== undefined) {
708
708
  bc = new BroadcastChannel(channelName);
709
709
  bc.addEventListener('message', onMessage);
710
710
  }
package/dist/index.min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.0.1
2
+ * @wxhccc/es-util v2.0.2
3
3
  * (c) 2022 wxhccc
4
4
  * @license MIT
5
5
  */
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)))},o=e=>"function"==typeof e,s=Array.isArray,i=e=>{const t=(r=e,n.call(r)).match(/^\[object (.*)\]$/);var r;return t?t[1]:""},a=e=>"Object"===i(e),c=(e,n)=>t.call(e,n);function l(e,t=[]){return{[e]:t}}const u=/^\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 d={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:i}={...t};let a,c,l=!1,u=!1;const d=e=>{c&&(c[0][c[1]]=e),a&&a(e)};if(r){const e=e=>s(e)&&2===e.length;e(r)?c=r:o(r)&&(a=r,e(i)&&(c=i)),l=!(!a&&!c),l&&(u=!!c&&c[0][c[1]])}let p;if(o(e)){const t=u?Promise.resolve(void 0):e();p=n?f(t):t}else p=n?f(e):e;return p instanceof Promise&&l&&!u&&(d(!0),p.finally((()=>d(!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?s(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(s(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 i=Object.keys(t),a={},c={};r(e,(t=>{i.includes(t)?a[t]=e[t]:c[t]=e[t]}));const l=Object.keys(a);if(0===l.length)return e;const{filterNullable:u,dateFormat:d}={filterNullable:!0,...n},f=l.reduce(((e,n)=>{const r=a[n],i=t[n];if(!r||!i)return e;if("join"===i||"pop"===i)s(r)&&r.length&&(e[n]="join"===i?r.join(","):r.slice(-1)[0]);else if(2===i.length||3===i.length){if(!r||2!==r.length)return e;const[t,n,s]=i,[a,c]=r;Object.assign(e,{[t]:o(d)?d(a,s):a,[n]:o(d)?d(c,s):c})}return e}),{}),p={...c,...f};return u?y(p):p},j=e=>"string"==typeof e,x=Symbol("NOMETHOD");function M(e){const t=new Map([[x,new Set]]),{name:n,customHanlderCreator:r}=e||{},s=o(r)?r(t):null,i=/\|-[a-z]+-\|/,a=(e,...t)=>{try{e(...t)}catch(e){console.error(e)}},c=o(s)?s:e=>{const{method:r,data:o,originEmitterName:s,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(i);r&&s&&r!==s||e.push(...t)}})),!e.length||n&&c&&n!==c||e.forEach((e=>a(e,o)))}const l=t.get(x);l&&l.forEach((t=>a(t,o,e)))},l=(e,t)=>{const{limitFrom:n="",namespace:r=""}=t||{};return(n||r)&&"string"==typeof e?`${e}|-from-|${n}|-ns-|${r}`:e},u=(e,t,r)=>j(e)?{method:e,data:t,...r&&j(r)?{targetEmitterName:r}:{},...n&&j(n)?{originEmitterName:n}:{}}:e;return{name:n,rootEventListener:c,on:(e,n,r)=>{if("symbol"==typeof e&&e!==x)return;const o=l(e,r);t.has(o)||t.set(o,new Set);t.get(o)?.add(n)},off:(e,n,r)=>{if("symbol"==typeof e&&e!==x)return;const{namespace:o}=r||{};if(o&&!e)return void t.forEach(((e,n)=>{"string"==typeof n&&n.endsWith(o)&&t.delete(n)}));const s=l(e,r);n?t.get(s)?.delete(n):t.delete(s)},emit:(...e)=>{const t=u(...e);c(t)},createPayload:u,removeAllListeners:()=>{t.clear()},getMethodNames:e=>{if(!e){const e=[];return t.forEach(((t,n)=>j(n)&&e.push(n.split(i)))),e}const n=[];return t.forEach(((e,t)=>j(t)&&n.push(t))),n},getListeners:(e,n)=>{if("symbol"==typeof e)return e===x?Array.from(t.get(x)||[]):[];const r=l(e,n),o=t.get(r);return o?Array.from(o):[]}}}e.ChinaIdCardValid=function(e){const t=e.toString().toUpperCase();return u.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 o=0,s=0,i=0;for(let t=0;t<17;t++)s=parseInt(e[t]),i=n[t],o+=s*i;return r[o%11].toString()===e[17]}return!0})()},e.NOMETHOD=x,e.array2tree=function(e,t={}){const{primaryKey:n,parentKey:r,childrenKey:i,createRoot:a,parentRefKey:u}={primaryKey:"id",parentKey:"pid",childrenKey:"children",createRoot:!1,parentRefKey:!1,...t},d=u&&("string"==typeof u?u:"_parent"),f={},p=[];return s(e)&&e.forEach((e=>{!c(f,e[n])&&(f[e[n]]=Object.assign({},e,l(i))),c(f,e[r])&&f[e[r]][i].push(Object.assign(f[e[n]],d?{[d]:f[e[r]]}:{})),!e[r]&&p.push(f[e[n]])})),o(a)?a(p):a?{[i]: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:o,precision:i,detail:a}=n;let c=parseFloat(e);if(!Number.isFinite(c))return;const l=c<0?-1:1;c=Math.abs(c);const{base:u,unitMap:d}=((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,o),f=e=>Number.isInteger(e)?e:e.toFixed(i);let p="",m=0;if(s(d))d.some((e=>{const t=Math.pow(u,e.expMax),n=c/t;return!(n>u)&&(p=e.units[r],m=f(n*l),!0)}));else{const e=Math.pow(u,d.expMax);p=d.units[r];m=f(c/e*l)}return a?{value:m,unit:p}:`${m} ${p}`},e.checkoutBy=function(e,t,n){return a(e)?s(t)?t.map((t=>e[t])):t&&a(t)?Object.keys(t).map((r=>{const o=t[r];return a(e[r])&&a(o)?n?n({},e[r],o):Object.assign({},e[r],o):o||e[r]})):Object.values(e):[]},e.createRAFTimer=e=>{const{autoStopWhenNoTask:t,autoStartWhenAddTask:n}={...e};let r=0,o=!0,s=0,i=0,a=[],c=!1;const l=e=>{const n=e-(i||e);i=e,s+=n,c&&(a=a.filter((e=>!e.needClear)),c=!1),!t||a.length?(a.forEach((e=>{const{callback:t,maxTime:r,runTime:o,elapsed:i,interval:a,needClear:l}=e;if(!l){if(r&&o>=r)return e.needClear=!0,void(c=!0);if(i>=a){try{t(s)}catch(e){}e.elapsed=0,e.runTime+=1}else e.elapsed+=n}})),r=window.requestAnimationFrame(l)):o=!0},u=()=>{r=window.requestAnimationFrame(l),o=!1},d=()=>{window.cancelAnimationFrame(r),o=!0};return{start:u,stop:d,pauseToggle:()=>{o?u():d()},addTask:(e,t,r)=>{e&&(n&&o&&u(),a.push({callback:e,elapsed:0,interval:t,maxTime:r,runTime:0}))},removeTask:e=>{a=a.filter((t=>t.callback!==e))},isPaused:()=>o}},e.eventTargetEmitter=M,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})()&&(!s(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 s(e)&&t&&n&&[t,n].every((e=>["string","function"].includes(typeof e)))&&e.forEach(((e,o)=>{const s="string"==typeof t?e[t]:t(e,o),i="string"==typeof n?e[n]:n(e,o);["string","number"].includes(typeof s)&&(r[s]=i)})),r},e.maskData=function(e,t){if("string"!=typeof e||!e)return"";const n=t&&t.mode&&d[t.mode]?d[t.mode]:{},{maskWith:r,startCharIndex:o=0,endCharIndex:s,startFrom:i,endUntil:a}={maskWith:"*",...n,...t};let c=e,l="",u="";const f=i?e.indexOf(i):-1;if(f>-1){const t=f+i.length;c=c.slice(t),l=e.slice(0,t)}const p=a?e.lastIndexOf(a):-1;p>-1&&(c=c.slice(0,p),u=e.slice(p));const m=c.split(""),h=[l],y=m.length,g=[o>=0?o:y+o,void 0!==s?s>=0?s:y+s:y-1];let[b,j]=g;return j=j>0&&j<y?j:y-1,b=b>=0&&b<=j?b:0,m.forEach(((e,t)=>{h.push(t>=b&&t<=j?r:e)})),h.push(u),h.join("")},e.pageCommunicate=function(e){const{messageHanlder:t,currentPage:n}=e||{},{emit:r,on:o,off:s,createPayload:i,removeAllListeners:a}=M({name:n,customHanlderCreator:t}),c=e=>r(e.data);let l;const u=window.localStorage,d="PAGE_COMMUNICATE_CHANNEL";if(void 0!==typeof BroadcastChannel)l=new BroadcastChannel(d),l.addEventListener("message",c);else{const e=()=>{const e=m(u.getItem(d)||"");e&&r(e)};window.addEventListener("storage",e)}return{on:o,off:s,send:(...e)=>{const t=i(...e);if(l)l.postMessage(t);else{const e=JSON.stringify({...t,ts:+new Date});u.setItem(d,e)}},destory:()=>{a(),l?l.close():u.removeItem(d)}}},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:o,hasParentKey:i,returnObject:a}=Object.assign({hasParentKey:!0,primaryKey:"id",parentKey:"pid",childrenKey:"children",returnObject:!1},t),c=a?{}:[];return s(e)||"object"==typeof e?(function e(t,l,u=!1){const d=i?{}:{[r]:l};if(!u){const e=Object.assign(d,function(e,t){const n={};for(const r in e)r!==t&&(n[r]=e[r]);return n}(t,o));a?c[t[n]]=e:c.push(e)}s(t[o])&&t[o].length&&t[o].forEach((r=>e(r,t[n])))}(s(e)?l(o,e):e,null,!0),c):c},e.wp=p,Object.defineProperty(e,"__esModule",{value:!0})}));
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)))},o=e=>"function"==typeof e,i=Array.isArray,s=e=>{const t=(r=e,n.call(r)).match(/^\[object (.*)\]$/);var r;return t?t[1]:""},a=e=>"Object"===s(e),c=(e,n)=>t.call(e,n);function l(e,t=[]){return{[e]:t}}const u=/^\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 d={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:s}={...t};let a,c,l=!1,u=!1;const d=e=>{c&&(c[0][c[1]]=e),a&&a(e)};if(r){const e=e=>i(e)&&2===e.length;e(r)?c=r:o(r)&&(a=r,e(s)&&(c=s)),l=!(!a&&!c),l&&(u=!!c&&c[0][c[1]])}let p;if(o(e)){const t=u?Promise.resolve(void 0):e();p=n?f(t):t}else p=n?f(e):e;return p instanceof Promise&&l&&!u&&(d(!0),p.finally((()=>d(!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 s=Object.keys(t),a={},c={};r(e,(t=>{s.includes(t)?a[t]=e[t]:c[t]=e[t]}));const l=Object.keys(a);if(0===l.length)return e;const{filterNullable:u,dateFormat:d}={filterNullable:!0,...n},f=l.reduce(((e,n)=>{const r=a[n],s=t[n];if(!r||!s)return e;if("join"===s||"pop"===s)i(r)&&r.length&&(e[n]="join"===s?r.join(","):r.slice(-1)[0]);else if(2===s.length||3===s.length){if(!r||2!==r.length)return e;const[t,n,i]=s,[a,c]=r;Object.assign(e,{[t]:o(d)?d(a,i):a,[n]:o(d)?d(c,i):c})}return e}),{}),p={...c,...f};return u?y(p):p},j=e=>"string"==typeof e,x=Symbol("NOMETHOD");function M(e){const t=new Map([[x,new Set]]),{name:n,customHanlderCreator:r}=e||{},i=o(r)?r(t):null,s=/\|-[a-z]+-\|/,a=(e,...t)=>{try{e(...t)}catch(e){console.error(e)}},c=o(i)?i:e=>{const{method:r,data:o,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(s);r&&i&&r!==i||e.push(...t)}})),!e.length||n&&c&&n!==c||e.forEach((e=>a(e,o)))}const l=t.get(x);l&&l.forEach((t=>a(t,o,e)))},l=(e,t)=>{const{limitFrom:n="",namespace:r=""}=t||{};return(n||r)&&"string"==typeof e?`${e}|-from-|${n}|-ns-|${r}`:e},u=(e,t,r)=>j(e)?{method:e,data:t,...r&&j(r)?{targetEmitterName:r}:{},...n&&j(n)?{originEmitterName:n}:{}}:e;return{name:n,rootEventListener:c,on:(e,n,r)=>{if("symbol"==typeof e&&e!==x)return;const o=l(e,r);t.has(o)||t.set(o,new Set);t.get(o)?.add(n)},off:(e,n,r)=>{if("symbol"==typeof e&&e!==x)return;const{namespace:o}=r||{};if(o&&!e)return void t.forEach(((e,n)=>{"string"==typeof n&&n.endsWith(o)&&t.delete(n)}));const i=l(e,r);n?t.get(i)?.delete(n):t.delete(i)},emit:(...e)=>{const t=u(...e);c(t)},createPayload:u,removeAllListeners:()=>{t.clear()},getMethodNames:e=>{if(!e){const e=[];return t.forEach(((t,n)=>j(n)&&e.push(n.split(s)))),e}const n=[];return t.forEach(((e,t)=>j(t)&&n.push(t))),n},getListeners:(e,n)=>{if("symbol"==typeof e)return e===x?Array.from(t.get(x)||[]):[];const r=l(e,n),o=t.get(r);return o?Array.from(o):[]}}}e.ChinaIdCardValid=function(e){const t=e.toString().toUpperCase();return u.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 o=0,i=0,s=0;for(let t=0;t<17;t++)i=parseInt(e[t]),s=n[t],o+=i*s;return r[o%11].toString()===e[17]}return!0})()},e.NOMETHOD=x,e.array2tree=function(e,t={}){const{primaryKey:n,parentKey:r,childrenKey:s,createRoot:a,parentRefKey:u}={primaryKey:"id",parentKey:"pid",childrenKey:"children",createRoot:!1,parentRefKey:!1,...t},d=u&&("string"==typeof u?u:"_parent"),f={},p=[];return i(e)&&e.forEach((e=>{!c(f,e[n])&&(f[e[n]]=Object.assign({},e,l(s))),c(f,e[r])&&f[e[r]][s].push(Object.assign(f[e[n]],d?{[d]:f[e[r]]}:{})),!e[r]&&p.push(f[e[n]])})),o(a)?a(p):a?{[s]: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:o,precision:s,detail:a}=n;let c=parseFloat(e);if(!Number.isFinite(c))return;const l=c<0?-1:1;c=Math.abs(c);const{base:u,unitMap:d}=((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,o),f=e=>Number.isInteger(e)?e:e.toFixed(s);let p="",m=0;if(i(d))d.some((e=>{const t=Math.pow(u,e.expMax),n=c/t;return!(n>u)&&(p=e.units[r],m=f(n*l),!0)}));else{const e=Math.pow(u,d.expMax);p=d.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 o=t[r];return a(e[r])&&a(o)?n?n({},e[r],o):Object.assign({},e[r],o):o||e[r]})):Object.values(e):[]},e.createRAFTimer=e=>{const{autoStopWhenNoTask:t,autoStartWhenAddTask:n}={...e};let r=0,o=!0,i=0,s=0,a=[],c=!1;const l=e=>{const n=e-(s||e);s=e,i+=n,c&&(a=a.filter((e=>!e.needClear)),c=!1),!t||a.length?(a.forEach((e=>{const{callback:t,maxTime:r,runTime:o,elapsed:s,interval:a,needClear:l}=e;if(!l){if(r&&o>=r)return e.needClear=!0,void(c=!0);if(s>=a){try{t(i)}catch(e){}e.elapsed=0,e.runTime+=1}else e.elapsed+=n}})),r=window.requestAnimationFrame(l)):o=!0},u=()=>{r=window.requestAnimationFrame(l),o=!1},d=()=>{window.cancelAnimationFrame(r),o=!0};return{start:u,stop:d,pauseToggle:()=>{o?u():d()},addTask:(e,t,r)=>{e&&(n&&o&&u(),a.push({callback:e,elapsed:0,interval:t,maxTime:r,runTime:0}))},removeTask:e=>{a=a.filter((t=>t.callback!==e))},isPaused:()=>o}},e.eventTargetEmitter=M,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,o)=>{const i="string"==typeof t?e[t]:t(e,o),s="string"==typeof n?e[n]:n(e,o);["string","number"].includes(typeof i)&&(r[i]=s)})),r},e.maskData=function(e,t){if("string"!=typeof e||!e)return"";const n=t&&t.mode&&d[t.mode]?d[t.mode]:{},{maskWith:r,startCharIndex:o=0,endCharIndex:i,startFrom:s,endUntil:a}={maskWith:"*",...n,...t};let c=e,l="",u="";const f=s?e.indexOf(s):-1;if(f>-1){const t=f+s.length;c=c.slice(t),l=e.slice(0,t)}const p=a?e.lastIndexOf(a):-1;p>-1&&(c=c.slice(0,p),u=e.slice(p));const m=c.split(""),h=[l],y=m.length,g=[o>=0?o:y+o,void 0!==i?i>=0?i:y+i:y-1];let[b,j]=g;return j=j>0&&j<y?j:y-1,b=b>=0&&b<=j?b:0,m.forEach(((e,t)=>{h.push(t>=b&&t<=j?r:e)})),h.push(u),h.join("")},e.pageCommunicate=function(e){const{messageHanlder:t,currentPage:n}=e||{},{emit:r,on:o,off:i,createPayload:s,removeAllListeners:a}=M({name:n,customHanlderCreator:t}),c=e=>r(e.data);let l;const u=window.localStorage,d="PAGE_COMMUNICATE_CHANNEL";if(void 0!==typeof window.BroadcastChannel)l=new BroadcastChannel(d),l.addEventListener("message",c);else{const e=()=>{const e=m(u.getItem(d)||"");e&&r(e)};window.addEventListener("storage",e)}return{on:o,off:i,send:(...e)=>{const t=s(...e);if(l)l.postMessage(t);else{const e=JSON.stringify({...t,ts:+new Date});u.setItem(d,e)}},destory:()=>{a(),l?l.close():u.removeItem(d)}}},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:o,hasParentKey:s,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,u=!1){const d=s?{}:{[r]:l};if(!u){const e=Object.assign(d,function(e,t){const n={};for(const r in e)r!==t&&(n[r]=e[r]);return n}(t,o));a?c[t[n]]=e:c.push(e)}i(t[o])&&t[o].length&&t[o].forEach((r=>e(r,t[n])))}(i(e)?l(o,e):e,null,!0),c):c},e.wp=p,Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.0.1
2
+ * @wxhccc/es-util v2.0.2
3
3
  * (c) 2022 wxhccc
4
4
  * @license MIT
5
5
  */
package/dist/optional.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.0.1
2
+ * @wxhccc/es-util v2.0.2
3
3
  * (c) 2022 wxhccc
4
4
  * @license MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.0.1
2
+ * @wxhccc/es-util v2.0.2
3
3
  * (c) 2022 wxhccc
4
4
  * @license MIT
5
5
  */
@@ -26,7 +26,7 @@ function pageCommunicate(options) {
26
26
  let bc;
27
27
  const ls = window.localStorage;
28
28
  const channelName = 'PAGE_COMMUNICATE_CHANNEL';
29
- if (typeof BroadcastChannel !== undefined) {
29
+ if (typeof window.BroadcastChannel !== undefined) {
30
30
  bc = new BroadcastChannel(channelName);
31
31
  bc.addEventListener('message', onMessage);
32
32
  }
package/dist/promise.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.0.1
2
+ * @wxhccc/es-util v2.0.2
3
3
  * (c) 2022 wxhccc
4
4
  * @license MIT
5
5
  */
package/dist/raf-timer.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.0.1
2
+ * @wxhccc/es-util v2.0.2
3
3
  * (c) 2022 wxhccc
4
4
  * @license MIT
5
5
  */
package/dist/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.0.1
2
+ * @wxhccc/es-util v2.0.2
3
3
  * (c) 2022 wxhccc
4
4
  * @license MIT
5
5
  */
package/dist/validate.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.0.1
2
+ * @wxhccc/es-util v2.0.2
3
3
  * (c) 2022 wxhccc
4
4
  * @license MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wxhccc/es-util v2.0.1
2
+ * @wxhccc/es-util v2.0.2
3
3
  * (c) 2022 wxhccc
4
4
  * @license MIT
5
5
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxhccc/es-util",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "A library that contains some useful methods",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",