@wxhccc/es-util 1.6.0 → 2.0.1

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.
Files changed (39) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +286 -57
  3. package/dist/array-tree-switch.d.ts +18 -2
  4. package/dist/date-time.d.ts +14 -0
  5. package/dist/event-target-emitter.d.ts +45 -0
  6. package/dist/event-target-emitter.js +147 -0
  7. package/dist/index.d.ts +4 -0
  8. package/dist/index.esm.js +499 -216
  9. package/dist/index.js +505 -218
  10. package/dist/index.min.js +2 -2
  11. package/dist/object-array.d.ts +7 -9
  12. package/dist/object-array.js +34 -16
  13. package/dist/optional.d.ts +6 -9
  14. package/dist/optional.js +136 -0
  15. package/dist/page-communicate.d.ts +27 -0
  16. package/dist/page-communicate.js +66 -0
  17. package/dist/promise.d.ts +21 -24
  18. package/dist/promise.js +24 -132
  19. package/dist/raf-timer.d.ts +36 -0
  20. package/dist/raf-timer.js +103 -0
  21. package/dist/types.d.ts +4 -0
  22. package/dist/utils.d.ts +10 -0
  23. package/dist/utils.js +30 -0
  24. package/dist/validate.js +54 -6
  25. package/dist/value-string-switch/byte-string.d.ts +9 -4
  26. package/dist/value-string-switch/index.d.ts +1 -0
  27. package/dist/value-string-switch/mask-data.d.ts +1 -2
  28. package/dist/value-string-switch/uri-b64.d.ts +8 -0
  29. package/dist/value-string-switch.js +28 -11
  30. package/package.json +19 -19
  31. package/types/array-tree-switch.d.ts +0 -49
  32. package/types/index.d.ts +0 -6
  33. package/types/object-array.d.ts +0 -33
  34. package/types/optional.d.ts +0 -50
  35. package/types/promise.d.ts +0 -44
  36. package/types/validate.d.ts +0 -2
  37. package/types/value-string-switch/byte-string.d.ts +0 -12
  38. package/types/value-string-switch/index.d.ts +0 -2
  39. package/types/value-string-switch/mask-data.d.ts +0 -22
package/dist/index.min.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @wxhccc/es-util v1.6.0
2
+ * @wxhccc/es-util v2.0.1
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).Smartfetch={})}(this,(function(e){"use strict";const{hasOwnProperty:t}=Object.prototype;function n(e,t=[]){return{[e]:t}}const r=/^\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 i={telphone:{startCharIndex:-8,endCharIndex:-5},idcard:{startCharIndex:-12,endCharIndex:-5}};const{hasOwnProperty:c,toString:o}=Object.prototype,s=e=>{const t=o.call(e).match(/^\[object (.*)\]$/);return t?t[1]:""};async function a(e){try{return[null,await e]}catch(e){return[e,void 0]}}const l={};function u(e,t){const n=function(e){return e?e._isVue||e.$&&e.$.vnode?"vue":"setState"in e?"react":"unknown":"unknown"}(this),r="unknown"!==n,i=r?this:l,o="react"===n?"state":"",u=o?i[o]:i,{wrap:f,lock:p,syncRefHandle:y,manualUnlock:d}="boolean"==typeof t?{wrap:t}:{...t};let h,b,j=[],g=!1,m=!1;const O=(e,t)=>!!e&&c.call(e,t),x=e=>"Object"===s(e),B=e=>{j.length?r?((e,t,r)=>{if("vue"===n&&i.$set&&!O(e,t[0]))return;const{$set:c=((e,t,n)=>{e[t]=n})}=i,o="react"===n,s=o?{...e}:e;let a=s,l=!1;for(let e=0;e<t.length;e++){const n=t[e],i=O(a,n);if(e===t.length-1){const e="boolean"==typeof a[n];l=!i||e,l&&c(a,n,r)}else{if(!i&&c(a,n,{}),!x(a[n]))break;o&&(a[n]={...a[n]}),a=a[n]}}o&&l&&i.setState({[t[0]]:s[t[0]]})})(u,j,e):l[p]=e:(b&&(b[0][b[1]]=e),h&&h(e))},k=()=>b?b[0][b[1]]:r||"string"!=typeof p?((e,t)=>{let n=!1;if(e&&x(e)&&Array.isArray(t)&&t.length){let r=e;for(let e=0;e<t.length;e++){const i=t[e];if("object"!=typeof r||!O(r,i))break;r=r[i],e===t.length-1&&(n="boolean"==typeof r&&r)}}return n})(u,j):u[p];if(p){const e=e=>Array.isArray(e)&&2===e.length;"string"==typeof p?j=p.split("."):e(p)?b=p:"function"==typeof p&&(h=p,e(y)&&(b=y)),g=j.length>0||!!b||!!h,g&&(m=k())}let A;A="function"==typeof e?m?(()=>{const e=Promise.resolve(void 0);return Object.assign(e,{then(...t){const[n]=t;return 2===t.length&&"function"==typeof n?n(void 0):e},catch:t=>e,finally:()=>e})})():f?a(e()):e():f?a(e):e;const K=()=>B(!1);return Object.defineProperties(A,{__lockValue:{get:k},_checkLockKey:{value:e=>l[e]},unlock:{value:K}}),g&&!m&&(B(!0),!d&&A.finally(K)),A}const f=Object.defineProperty(u,"_checkLockKey",{value:e=>l[e]}),p={install(e,t="$wp"){e.config&&"globalProperties"in e.config?e.config.globalProperties[t]=u:e.prototype[t]=u}};const y=(e,t)=>{const n={};return Object.keys(e).forEach((r=>{const i=e[r];""!==i&&null!=i&&(n[r]=t&&"[object Object]"===Object.prototype.toString.call(i)?y(i):i)})),n},{toString:d}=Object.prototype,h=e=>{if(null!==e)return Array.isArray(e)?e.map(h):("[object Object]"===d.call(e)&&Object.keys(e).forEach((t=>{e[t]=h(e[t])})),e)},b=(e,t,n)=>{const r=Object.keys(t),i={},c={};Object.keys(e).forEach((t=>{r.includes(t)?i[t]=e[t]:c[t]=e[t]}));const o=Object.keys(i);if(0===o.length)return e;const{filterNullable:s,dateFormat:a}={filterNullable:!0,...n},l=o.reduce(((e,n)=>{const r=i[n],c=t[n];if(!r||!c)return e;if("join"===c||"pop"===c)Array.isArray(r)&&r.length&&(e[n]="join"===c?r.join(","):r.slice(-1)[0]);else if(2===c.length||3===c.length){if(!r||2!==r.length)return e;const[t,n,i]=c,[o,s]=r;Object.assign(e,{[t]:a instanceof Function?a(o,i):o,[n]:a instanceof Function?a(s,i):s})}return e}),{}),u={...c,...l};return s?y(u):u};e.ChinaIdCardValid=function(e){const t=e.toString().toUpperCase();return r.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 i=0,c=0,o=0;for(let t=0;t<17;t++)c=parseInt(e[t]),o=n[t],i+=c*o;return r[i%11].toString()===e[17]}return!0})()},e.array2tree=function(e,r={}){const{primaryKey:i,parentKey:c,childrenKey:o,createRoot:s,parentRefKey:a}=Object.assign({primaryKey:"id",parentKey:"pid",childrenKey:"children",createRoot:!1,parentRefKey:!1},r),l=a&&("string"==typeof a?a:"_parent");let u={},f=[];return Array.isArray(e)&&e.forEach((e=>{!t.call(u,e[i])&&(u[e[i]]=Object.assign({},e,n(o))),t.call(u,e[c])&&u[e[c]][o].push(Object.assign(u[e[i]],l?{[l]:u[e[c]]}:{})),!e[c]&&f.push(u[e[i]])})),"function"==typeof s?s(f):s?{[o]:f}:f},e.awaitWrapper=a,e.byteParse=function(e,t={}){},e.byteStringify=function(e,t){const n=Object.assign({standard:"jedec",unitLvl:"auto",precision:1,detail:!1},t),{standard:r,unitLvl:i,precision:c,detail:o}=n;let s=parseFloat(e);if(!Number.isFinite(s))return;const a=s<0?-1:1;s=Math.abs(s);const{base:l,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,i),f=e=>Number.isInteger(e)?e:e.toFixed(c);let p="",y=0;if(Array.isArray(u))u.some((e=>{const t=Math.pow(l,e.expMax),n=s/t;return!(n>l)&&(p=e.units[r],y=f(n*a),!0)}));else{const e=Math.pow(l,u.expMax);p=u.units[r];y=f(s/e*a)}return o?{value:y,unit:p}:`${y} ${p}`},e.checkoutBy=function(e,t,n){return e instanceof Object?Array.isArray(t)?t.map((t=>e[t])):t&&t instanceof Object?Object.keys(t).map((r=>e[r]instanceof Object&&t[r]instanceof Object?n?n({},e[r],t[r]):Object.assign({},e[r],t[r]):t[r]||e[r])):Object.values(e):[]},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)&&(()=>{let 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})()&&(!Array.isArray(t)||(n=t,e.replace(/[()+\-*/]{1,}/g,"`").split("`").every((e=>!/[A-Z]/i.test(e)||n.includes(e)))));var n},e.isNullable=e=>""===e||null==e,e.mapToObject=function(e,t="key",n="value"){let r={};return Array.isArray(e)&&t&&n&&[t,n].every((e=>["string","function"].includes(typeof e)))&&e.forEach(((e,i)=>{const c="string"==typeof t?e[t]:t(e,i),o="string"==typeof n?e[n]:n(e,i);["string","number"].includes(typeof c)&&(r[c]=o)})),r},e.maskData=function(e,t){if("string"!=typeof e||!e)return"";const n=t&&t.mode&&i[t.mode]?i[t.mode]:{},{maskWith:r,startCharIndex:c=0,endCharIndex:o,startFrom:s,endUntil:a}={maskWith:"*",...n,...t};let l=e,u="",f="";const p=s?e.indexOf(s):-1;if(p>-1){const t=p+s.length;l=l.slice(t),u=e.slice(0,t)}const y=a?e.lastIndexOf(a):-1;y>-1&&(l=l.slice(0,y),f=e.slice(y));const d=l.split(""),h=[u],b=d.length,j=[c>=0?c:b+c,void 0!==o?o>=0?o:b+o:b-1];let[g,m]=j;return m=m>0&&m<b?m:b-1,g=g>=0&&g<=m?g:0,d.forEach(((e,t)=>{h.push(t>=g&&t<=m?r:e)})),h.push(f),h.join("")},e.objType=s,e.pickRenameKeys=function(e,t){if(!(e&&e instanceof Object&&t&&t instanceof Object))return;let n={};for(let r in e)r in t&&(n[t[r]]=e[r]);return n},e.safeJsonParse=function(e="",t){try{return JSON.parse(e)}catch(e){return t}},e.switchNullToUndefined=h,e.tree2array=function(e,t={}){const{primaryKey:r,parentKey:i,childrenKey:c,hasParentKey:o,returnObject:s}=Object.assign({hasParentKey:!0,primaryKey:"id",parentKey:"pid",childrenKey:"children",returnObject:!1},t);let a=s?{}:[];return Array.isArray(e)||"object"==typeof e?(function e(t,n,l=!1){let u=o?{}:{[i]:n};if(!l){const e=Object.assign(u,function(e,t){let n={};for(let r in e)r!==t&&(n[r]=e[r]);return n}(t,c));s?a[t[r]]=e:a.push(e)}Array.isArray(t[c])&&t[c].length&&t[c].forEach((n=>e(n,t[r])))}(Array.isArray(e)?n(c,e):e,null,!0),a):a},e.wp=f,e.wpVuePlugin=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,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})}));
@@ -1,6 +1,4 @@
1
- declare type Obj = {
2
- [key: string]: any;
3
- };
1
+ import { AnyObject } from './types';
4
2
  /**
5
3
  * translate object array to key-value map object
6
4
  *
@@ -11,23 +9,23 @@ declare type Obj = {
11
9
  interface PropHandler {
12
10
  (item: any, index: number): string;
13
11
  }
14
- export declare function mapToObject(objectArray: any[], keyProp?: string | PropHandler, valueProp?: string | PropHandler): Obj;
12
+ export declare function mapToObject(objectArray: AnyObject[], keyProp?: string | PropHandler, valueProp?: string | PropHandler): Record<string, string | number>;
13
+ declare type MergeFn = <T>(...args: T[]) => T;
15
14
  /**
16
15
  * checkout values form object as an array
17
- *
16
+ * 从对象中挑选指定的值并以数组形式返回,必要时可使用自定义属性覆盖选中对象
18
17
  * @param {Object} object
19
18
  * @param {string[] | Object} keys
20
19
  * @param {string} valueProp
21
20
  */
22
- declare type MergeFn = <T>(...args: T[]) => T;
23
- export declare function checkoutBy(object: Obj, keys?: string[] | Obj, mergeFn?: MergeFn): any[];
21
+ export declare function checkoutBy<T extends AnyObject = AnyObject, K extends string & keyof T = Extract<keyof T, 'string'>>(object: T, keys?: K[] | Record<string, any>, mergeFn?: MergeFn): any[];
24
22
  /**
25
23
  * pick and rename object values
26
24
  *
27
25
  * @param {Object} object
28
26
  * @param {Object} keysMap
29
27
  */
30
- export declare function pickRenameKeys(object: Obj, keysMap: {
28
+ export declare function pickRenameKeys(object: AnyObject, keysMap: {
31
29
  [key: string]: string;
32
- }): Obj | undefined;
30
+ }): AnyObject | undefined;
33
31
  export {};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wxhccc/es-util v1.6.0
2
+ * @wxhccc/es-util v2.0.1
3
3
  * (c) 2022 wxhccc
4
4
  * @license MIT
5
5
  */
@@ -7,27 +7,44 @@
7
7
 
8
8
  Object.defineProperty(exports, '__esModule', { value: true });
9
9
 
10
+ var utils = require('./utils.js');
11
+
10
12
  function mapToObject(objectArray, keyProp = 'key', valueProp = 'value') {
11
- let result = {};
12
- Array.isArray(objectArray) && keyProp && valueProp
13
- && [keyProp, valueProp].every(val => ['string', 'function'].includes(typeof val))
14
- && objectArray.forEach((item, index) => {
13
+ const result = {};
14
+ utils.isArr(objectArray) &&
15
+ keyProp &&
16
+ valueProp &&
17
+ [keyProp, valueProp].every((val) => ['string', 'function'].includes(typeof val)) &&
18
+ objectArray.forEach((item, index) => {
15
19
  const key = typeof keyProp === 'string' ? item[keyProp] : keyProp(item, index);
16
20
  const value = typeof valueProp === 'string' ? item[valueProp] : valueProp(item, index);
17
21
  ['string', 'number'].includes(typeof key) && (result[key] = value);
18
22
  });
19
23
  return result;
20
24
  }
25
+ /**
26
+ * checkout values form object as an array
27
+ * 从对象中挑选指定的值并以数组形式返回,必要时可使用自定义属性覆盖选中对象
28
+ * @param {Object} object
29
+ * @param {string[] | Object} keys
30
+ * @param {string} valueProp
31
+ */
21
32
  function checkoutBy(object, keys, mergeFn) {
22
- if (!(object instanceof Object))
33
+ if (!utils.isObj(object)) {
23
34
  return [];
24
- if (Array.isArray(keys)) {
25
- return keys.map(item => (object[item]));
26
35
  }
27
- else if (keys && keys instanceof Object) {
28
- return Object.keys(keys).map(item => (object[item] instanceof Object && keys[item] instanceof Object)
29
- ? (mergeFn ? mergeFn({}, object[item], keys[item]) : Object.assign({}, object[item], keys[item]))
30
- : (keys[item] || object[item]));
36
+ if (utils.isArr(keys)) {
37
+ return keys.map((key) => object[key]);
38
+ }
39
+ else if (keys && utils.isObj(keys)) {
40
+ return Object.keys(keys).map((key) => {
41
+ const value = keys[key];
42
+ return utils.isObj(object[key]) && utils.isObj(value)
43
+ ? mergeFn
44
+ ? mergeFn({}, object[key], value)
45
+ : Object.assign({}, object[key], value)
46
+ : value || object[key];
47
+ });
31
48
  }
32
49
  return Object.values(object);
33
50
  }
@@ -38,11 +55,12 @@ function checkoutBy(object, keys, mergeFn) {
38
55
  * @param {Object} keysMap
39
56
  */
40
57
  function pickRenameKeys(object, keysMap) {
41
- if (!object || !(object instanceof Object) || !keysMap || !(keysMap instanceof Object))
58
+ if (!object || !utils.isObj(object) || !keysMap || !utils.isObj(keysMap)) {
42
59
  return;
43
- let result = {};
44
- for (let i in object) {
45
- (i in keysMap) && (result[keysMap[i]] = object[i]);
60
+ }
61
+ const result = {};
62
+ for (const i in object) {
63
+ i in keysMap && (result[keysMap[i]] = object[i]);
46
64
  }
47
65
  return result;
48
66
  }
@@ -17,9 +17,9 @@ export declare const isNullable: (value: unknown) => value is "" | null | undefi
17
17
  * @param deep 是否需要递归过滤
18
18
  * @returns 过滤后的对象
19
19
  */
20
- export declare const filterNullable: <T extends AnyObject>(obj: T, deep?: boolean | undefined) => T;
20
+ export declare const filterNullable: <T extends AnyObject>(obj: T, deep?: boolean) => T;
21
21
  /**
22
- * 将对象中属性值为null的转换为undefined
22
+ * 将对象中属性值为null的转换为undefined,会返回一个浅拷贝的新对象
23
23
  * @param data 对象数据
24
24
  * @returns
25
25
  */
@@ -28,10 +28,7 @@ export declare const switchNullToUndefined: (data: any) => any;
28
28
  * 参数转换规则的配置对象
29
29
  * 值可以是时间范围转换所需的开始,结束时间字段的名称,或者需要进行拼接的数组
30
30
  */
31
- export declare type ParamsSwitchMaps<DK extends string = string, RK extends string = string> = Record<DK, [
32
- RK,
33
- RK
34
- ] | [RK, RK, string] | 'join' | 'pop'>;
31
+ export declare type ParamsSwitchMaps<DK extends string = string, RK extends string = string> = Record<DK, [RK, RK] | [RK, RK, string] | 'join' | 'pop'>;
35
32
  export declare type DateFormat = (date: any, format?: string) => string;
36
33
  /**
37
34
  * 将搜素条件里的数组字段转换为其他格式,通常用于搜索表单的字段转换
@@ -41,10 +38,10 @@ export declare type DateFormat = (date: any, format?: string) => string;
41
38
  */
42
39
  export declare const formParamsSwitch: <R extends AnyObject = AnyObject, T extends AnyObject = AnyObject>(formData: T, maps: Partial<ParamsSwitchMaps<Exclude<keyof T, number | symbol>, Exclude<keyof R, number | symbol>>>, options?: {
43
40
  /** 是否需要过滤空数据 */
44
- filterNullable?: boolean | undefined;
41
+ filterNullable?: boolean;
45
42
  /** 时间格式换函数 */
46
- dateFormat?: DateFormat | undefined;
47
- } | undefined) => R;
43
+ dateFormat?: DateFormat;
44
+ }) => R;
48
45
  /** 创建一个绑定了默认时间格式转换函数的formParamsSwitch函数 */
49
46
  export declare const formParamsSwitchCreator: (dateFormat: DateFormat) => typeof formParamsSwitch;
50
47
  export {};
@@ -0,0 +1,136 @@
1
+ /*!
2
+ * @wxhccc/es-util v2.0.1
3
+ * (c) 2022 wxhccc
4
+ * @license MIT
5
+ */
6
+ 'use strict';
7
+
8
+ Object.defineProperty(exports, '__esModule', { value: true });
9
+
10
+ var utils = require('./utils.js');
11
+
12
+ function safeJsonParse(json = '', faileValue) {
13
+ try {
14
+ return JSON.parse(json);
15
+ }
16
+ catch (_e) {
17
+ return faileValue;
18
+ }
19
+ }
20
+ /**
21
+ * check value whether empty text
22
+ * 判断给定变量是否是字面量空值 */
23
+ const isNullable = (value) => value === '' || value === undefined || value === null;
24
+ /**
25
+ * 过滤对象中属性为空('' | undefined | null)的字段
26
+ * @param obj 给定对象
27
+ * @param deep 是否需要递归过滤
28
+ * @returns 过滤后的对象
29
+ */
30
+ const filterNullable = (obj, deep) => {
31
+ const result = {};
32
+ utils.objForEch(obj, (key, value) => {
33
+ if (!isNullable(value)) {
34
+ if (!deep) {
35
+ result[key] = value;
36
+ }
37
+ else if (utils.isArr(value)) {
38
+ result[key] = value.map((item) => utils.isObj(item) ? filterNullable(item) : item);
39
+ }
40
+ else {
41
+ result[key] = utils.isObj(value) ? filterNullable(value) : value;
42
+ }
43
+ }
44
+ });
45
+ return result;
46
+ };
47
+ /**
48
+ * 将对象中属性值为null的转换为undefined,会返回一个浅拷贝的新对象
49
+ * @param data 对象数据
50
+ * @returns
51
+ */
52
+ const switchNullToUndefined = (data) => {
53
+ if (data === null) {
54
+ return undefined;
55
+ }
56
+ if (utils.isArr(data)) {
57
+ return data.map(switchNullToUndefined);
58
+ }
59
+ else if (utils.isObj(data)) {
60
+ const result = {};
61
+ utils.objForEch(data, (key, value) => {
62
+ result[key] = switchNullToUndefined(value);
63
+ });
64
+ return result;
65
+ }
66
+ return data;
67
+ };
68
+ /**
69
+ * 将搜素条件里的数组字段转换为其他格式,通常用于搜索表单的字段转换
70
+ * @param formData 传入参数
71
+ * @param maps 转换的映射关系,eg:{ date: ['startTime', 'endTime'] }
72
+ * @param options 额外的配置参数
73
+ */
74
+ const formParamsSwitch = (formData, maps, options) => {
75
+ const dateKeys = Object.keys(maps);
76
+ const dateData = {};
77
+ const restData = {};
78
+ utils.objForEch(formData, (key) => {
79
+ if (dateKeys.includes(key)) {
80
+ dateData[key] = formData[key];
81
+ }
82
+ else {
83
+ restData[key] = formData[key];
84
+ }
85
+ });
86
+ const accessKeys = Object.keys(dateData);
87
+ // 如无需要转换的数据时,直接返回原对象
88
+ if (accessKeys.length === 0) {
89
+ return formData;
90
+ }
91
+ const { filterNullable: filterNullableValue, dateFormat } = {
92
+ filterNullable: true,
93
+ ...options
94
+ };
95
+ const handleData = accessKeys.reduce((acc, key) => {
96
+ const values = dateData[key];
97
+ const mapValue = maps[key];
98
+ if (!values || !mapValue) {
99
+ return acc;
100
+ }
101
+ // 数组合并操作/取最后一位操作
102
+ if (mapValue === 'join' || mapValue === 'pop') {
103
+ if (utils.isArr(values) && values.length) {
104
+ acc[key] = mapValue === 'join' ? values.join(',') : values.slice(-1)[0];
105
+ }
106
+ }
107
+ else if (mapValue.length === 2 || mapValue.length === 3) {
108
+ if (!values || values.length !== 2) {
109
+ return acc;
110
+ }
111
+ const [startKey, endKey, format] = mapValue;
112
+ const [startValue, endValue] = values;
113
+ Object.assign(acc, {
114
+ [startKey]: utils.isFn(dateFormat)
115
+ ? dateFormat(startValue, format)
116
+ : startValue,
117
+ [endKey]: utils.isFn(dateFormat) ? dateFormat(endValue, format) : endValue
118
+ });
119
+ }
120
+ return acc;
121
+ }, {});
122
+ const result = {
123
+ ...restData,
124
+ ...handleData
125
+ };
126
+ return filterNullableValue ? filterNullable(result) : result;
127
+ };
128
+ /** 创建一个绑定了默认时间格式转换函数的formParamsSwitch函数 */
129
+ const formParamsSwitchCreator = (dateFormat) => (formData, maps, options) => formParamsSwitch(formData, maps, { dateFormat, ...options });
130
+
131
+ exports.filterNullable = filterNullable;
132
+ exports.formParamsSwitch = formParamsSwitch;
133
+ exports.formParamsSwitchCreator = formParamsSwitchCreator;
134
+ exports.isNullable = isNullable;
135
+ exports.safeJsonParse = safeJsonParse;
136
+ exports.switchNullToUndefined = switchNullToUndefined;
@@ -0,0 +1,27 @@
1
+ import { EventPayload as OrgEventPayload, ConfigOptions as OrgCfgOps } from './event-target-emitter';
2
+ export { NOMETHOD } from './event-target-emitter';
3
+ export interface PcEventPayload<T = any> extends Omit<OrgEventPayload, 'originEmitterName' | 'targetEmitterName'> {
4
+ /** 从哪个页面发送 */
5
+ from?: string;
6
+ /** 指定哪个页面接收 */
7
+ to?: string;
8
+ }
9
+ export interface PcConfigOptions {
10
+ /** 当前页面name */
11
+ currentPage?: string;
12
+ /** 自定义消息处理逻辑 */
13
+ messageHanlder?: OrgCfgOps['customHanlderCreator'];
14
+ }
15
+ /**
16
+ * 创建同源页面之间通信的封装实例,默认使用BroadcastChannel实现,在不支持的浏览器环境中会使用localstorage实现
17
+ * @param options 配置对象
18
+ * @returns
19
+ */
20
+ export declare function pageCommunicate(options?: PcConfigOptions): {
21
+ on: <T>(method: string | symbol, listener: (data: T) => any, options?: import("./event-target-emitter").BindOptions | undefined) => void;
22
+ off: (method: string | symbol, callback?: import("./types").AnyFunction<any> | undefined, options?: import("./event-target-emitter").BindOptions | undefined) => void;
23
+ send: (methodOrPayload: string | OrgEventPayload<any>, data?: any, target?: string | undefined) => void;
24
+ destory: () => void;
25
+ };
26
+ export declare type BccnInstance = ReturnType<typeof pageCommunicate>;
27
+ export default pageCommunicate;
@@ -0,0 +1,66 @@
1
+ /*!
2
+ * @wxhccc/es-util v2.0.1
3
+ * (c) 2022 wxhccc
4
+ * @license MIT
5
+ */
6
+ 'use strict';
7
+
8
+ Object.defineProperty(exports, '__esModule', { value: true });
9
+
10
+ var optional = require('./optional.js');
11
+ var eventTargetEmitter = require('./event-target-emitter.js');
12
+ require('./utils.js');
13
+
14
+ /**
15
+ * 创建同源页面之间通信的封装实例,默认使用BroadcastChannel实现,在不支持的浏览器环境中会使用localstorage实现
16
+ * @param options 配置对象
17
+ * @returns
18
+ */
19
+ function pageCommunicate(options) {
20
+ const { messageHanlder, currentPage } = options || {};
21
+ const { emit, on, off, createPayload, removeAllListeners } = eventTargetEmitter.eventTargetEmitter({
22
+ name: currentPage,
23
+ customHanlderCreator: messageHanlder
24
+ });
25
+ const onMessage = (event) => emit(event.data);
26
+ let bc;
27
+ const ls = window.localStorage;
28
+ const channelName = 'PAGE_COMMUNICATE_CHANNEL';
29
+ if (typeof BroadcastChannel !== undefined) {
30
+ bc = new BroadcastChannel(channelName);
31
+ bc.addEventListener('message', onMessage);
32
+ }
33
+ else {
34
+ const onStorageMessage = () => {
35
+ const payload = optional.safeJsonParse(ls.getItem(channelName) || '');
36
+ if (payload) {
37
+ emit(payload);
38
+ }
39
+ };
40
+ window.addEventListener('storage', onStorageMessage);
41
+ }
42
+ const send = (...args) => {
43
+ const payload = createPayload(...args);
44
+ if (bc) {
45
+ bc.postMessage(payload);
46
+ }
47
+ else {
48
+ const payloadWitchTs = JSON.stringify({ ...payload, ts: +new Date() });
49
+ ls.setItem(channelName, payloadWitchTs);
50
+ }
51
+ };
52
+ const destory = () => {
53
+ removeAllListeners();
54
+ if (bc) {
55
+ bc.close();
56
+ }
57
+ else {
58
+ ls.removeItem(channelName);
59
+ }
60
+ };
61
+ return { on, off, send, destory };
62
+ }
63
+
64
+ exports.NOMETHOD = eventTargetEmitter.NOMETHOD;
65
+ exports["default"] = pageCommunicate;
66
+ exports.pageCommunicate = pageCommunicate;
package/dist/promise.d.ts CHANGED
@@ -1,44 +1,41 @@
1
- export declare const objType: (val: unknown) => string;
2
1
  /**
3
2
  * wrap promise and handle reject or err by return an array like [error, undefined]
4
3
  * @param promise promise
5
4
  * @returns Promise<[K, undefined] | [null, T]>
6
5
  */
7
6
  export declare function awaitWrapper<T, K = Error>(promise: Promise<T>): Promise<[null, T] | [K, undefined]>;
8
- export declare type SyncRefHandle = [Record<string, boolean>, string];
9
- export declare type LockSwitchHook = (val: boolean) => unknown;
10
- export interface PromiseWithLock<T> extends Promise<T> {
11
- readonly __lockValue: boolean;
12
- unlock: () => void;
13
- }
14
- export declare type ContextType = 'react' | 'vue' | 'unknown';
7
+ /** 防止多次promise函数运行控制器,对于响应式系统,可以同时用作BoolSwitch */
8
+ export declare type LockRefHandle<T extends {
9
+ [key: string]: boolean;
10
+ } = Record<string, boolean>> = [T, string];
11
+ /** loading等状态的切换函数 */
12
+ export declare type BoolSwitch = (val: boolean) => unknown;
15
13
  /**
16
14
  * wrap promise with lock, support reactive environment like react or vue
17
15
  * @param promise promise
18
16
  * @param wrap whether use awaitWrap to wrap result
19
17
  */
20
18
  export interface WpOptions {
19
+ /** whether use `awaitWrapper` to wrap then promise. */
21
20
  wrap?: boolean;
22
- lock?: string | LockSwitchHook | SyncRefHandle;
23
- syncRefHandle?: SyncRefHandle;
24
- manualUnlock?: boolean;
21
+ /** useful in Hook / Composition Api, you can pass setXXX to method */
22
+ lock?: BoolSwitch | LockRefHandle;
23
+ /** when you need function and syncRefHandle at sametime, in react hooks */
24
+ syncRefHandle?: LockRefHandle;
25
25
  }
26
- declare type WpReturn<T> = PromiseWithLock<T | undefined>;
27
- declare type WpArrReturn<T> = PromiseWithLock<[null, T] | [Error, undefined]>;
26
+ declare type WpReturn<T> = Promise<T | undefined>;
27
+ declare type WpArrReturn<T> = Promise<[null, T] | [Error, undefined]>;
28
+ declare type WpMayLockArrReturn<T> = Promise<[null, T] | [Error, undefined]>;
28
29
  declare type WpPromise<T> = Promise<T> | (() => Promise<T>);
29
- declare function wrapPromise<T>(this: any, promise: WpPromise<T>, wrap?: false): WpReturn<T>;
30
- declare function wrapPromise<T>(this: any, promise: WpPromise<T>, wrap: true): WpArrReturn<T>;
31
- declare function wrapPromise<T>(this: any, promise: WpPromise<T>, options?: WpOptions & {
30
+ declare function wrapPromise<T>(promise: WpPromise<T>, options?: WpOptions & {
32
31
  wrap?: false;
33
32
  }): WpReturn<T>;
34
- declare function wrapPromise<T>(this: any, promise: WpPromise<T>, options?: WpOptions & {
33
+ declare function wrapPromise<T>(promise: Promise<T>, options?: WpOptions & {
35
34
  wrap: true;
36
35
  }): WpArrReturn<T>;
37
- declare type WP = typeof wrapPromise & {
38
- _checkLockKey: (key: string) => boolean;
39
- };
40
- export declare const wp: WP;
41
- export declare const wpVuePlugin: {
42
- install(appOrVue: any, key?: string): void;
43
- };
36
+ declare function wrapPromise<T>(promise: () => Promise<T>, options?: WpOptions & {
37
+ wrap: true;
38
+ }): WpMayLockArrReturn<T>;
39
+ /** short for method `wrapPromise` */
40
+ export declare const wp: typeof wrapPromise;
44
41
  export {};