utils-lib-js-lite 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { ICatchAwait, IThrottle, IDebounce, IDefer, IRequestFrame } from "./types";
1
+ import { ICatchAwait, IDebounce, IDefer, IRequestFrame, IThrottle } from "./types";
2
2
  export declare const throttle: IThrottle;
3
3
  export declare const debounce: IDebounce;
4
4
  export declare const defer: IDefer;
@@ -1 +1 @@
1
- var UtilsLib=function(t){"use strict";var e,n=function(){return n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function r(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}t.types=void 0,(e=t.types||(t.types={}))["[object Array]"]="array",e["[object Object]"]="object",e["[object Function]"]="function",e["[object Set]"]="set",e["[object Map]"]="map",e["[object WeakMap]"]="weakMap",e["[object WeakSet]"]="weakSet",e["[object Date]"]="date",e["[object RegExp]"]="regExp",e["[object Math]"]="math";var o={types:t.types},i=function(t,e,n){return void 0===n&&(n=!1),Math.floor(Math.random()*(e-t+(n?1:0))+t)},a=function(t){var e={};return t.includes("?")?(t.split("?")[1].split("&").forEach((function(t){var n=t.split("=")[0];e[n]=t.split("=")[1]})),e):e},c=function(t,e){void 0===e&&(e={});var n=Object.keys(e);if(0===n.length)return t;var r=n.map((function(t){return"".concat(t,"=").concat(e[t])}));return"".concat(t).concat(t.includes("?")?"&":"?").concat(r.join("&"))},u=function(e){var n=typeof e;if(null===e)return"null";if("object"===n){var r=Object.prototype.toString.call(e);return t.types[r]}return n},l=function(t,e){void 0===e&&(e=[]);var n=u(t);return e.includes(n)},s=function(t,e){return void 0===e&&(e="-"),t.replace(/[A-Z]/g,(function(t){return"".concat(e).concat(t.toLowerCase())}))},f={randomNum:i,urlSplit:a,urlJoin:c,getType:u,getTypeByList:l,toKebabCase:s},p=function(t,e,n){void 0===n&&(n="");for(var r=0,o=e.split(".");r<o.length;r++){if(void 0===(t=t[o[r]]))return n}return t},v=function(t,e,n){void 0===n&&(n={});for(var r=e.split("."),o=r[r.length-1],i=t,a=0,c=r;a<c.length;a++){var u=c[a];if("object"!=typeof i&&void 0!==i)return t;!i&&(i={}),!i[u]&&(i[u]={}),o===u&&(i[o]=n),i=i[u]}return t},d=function(t,e,n){var r;for(var o in void 0===e&&(e={}),void 0===n&&(n=!1),e)for(var i in e[o]){var a=null!==(r=null==t?void 0:t.prototype)&&void 0!==r?r:t;(void 0===(null==t?void 0:t[i])||n)&&(a[i]=e[o][i])}return t},h=function(t){for(var e in t){var n=t[e];"string"!=typeof n||t[n]||(t[n]=e)}return t},y=function(t,e){return"object"!=typeof t||"null"===e},m=function(t){var e=u(t);if(y(t,e))return t;var n=b(e,t);return"map"===e?t.forEach((function(t,e){n.set(e,m(t))})):"set"===e?t.forEach((function(t){n.add(m(t))})):Reflect.ownKeys(t).forEach((function(e){var r=t[e];n[e]=m(r)})),n},b=function(t,e){switch(void 0===e&&(e={}),t){case"array":return[];case"function":return e;case"set":return new Set;case"map":return new Map;case"date":return new Date(e);case"regExp":return new RegExp(e);case"math":return Math;default:return{}}},g=function(t){function e(){}return e.prototype=t,new e},w=function(t,e){return void 0===e&&(e=function(){}),e.prototype=g(t.prototype),e.prototype.super=t,e.prototype.constructor=e,e},j=function(t,e){void 0===e&&(e=!1);for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];return t._instance&&!e||(t._instance=new(t.bind.apply(t,r([void 0],n,!1)))),t._instance},E=function(t){return function(e){for(var n in t)Reflect.has(e.prototype,n)||(e.prototype[n]=t[n])}},O=function(t){if("string"!==u(t))return null;try{return JSON.parse(t)}catch(t){return null}},S=function(t){if(!l(t,["array","object","set","map"]))return"";try{return JSON.stringify(t)}catch(t){return""}},A=function(t){return t&&t===t.window},L=function(t){void 0===t&&(t={});var e=Object.create(null);return Reflect.ownKeys(t).forEach((function(n){return e[n]=t[n]})),e},M=function(t){void 0===t&&(t={});var e=L(t);return Reflect.ownKeys(e).length<=0},T={getValue:p,setValue:v,mixIn:d,enumInversion:h,isNotObject:y,cloneDeep:m,createObjectVariable:b,createObject:g,inherit:w,getInstance:j,classDecorator:E,stringToJson:O,jsonToString:S,isWindow:A,emptyObject:L,isEmptyObject:M},D=function(t){return t.sort((function(){return Math.random()-.5}))},B=function(t){return Array.from(new Set(t))},I=function(t,e){return void 0===e&&(e=[]),t.forEach((function(t){return"array"===u(t)?I(t,e):e.push(t)})),e},N=function(t,e){return void 0===e&&(e=0),{item:t[e],current:(e+1)%t.length}},k={arrayRandom:D,arrayUniq:B,arrayDemote:I,arrayLoop:N},x=void 0,J=function(t,e){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n||(n=setTimeout((function(){t.call.apply(t,r([x],o,!1)),n=null}),e))}},R=function(t,e){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n&&(clearTimeout(n),n=null),n=setTimeout((function(){t.call.apply(t,r([x],o,!1))}),e)}},q=function(t){var e,n;return void 0===t&&(t=0),{promise:new Promise((function(r,o){e=r,n=o,t>0&&setTimeout((function(){return n("timeout")}),t)})),resolve:e,reject:n}},F=function(t){return t.then((function(t){return[null,t]})).catch((function(t){return[t]}))},V={throttle:J,debounce:R,defer:q,catchAwait:F},z=function(t){var e,n,r=t.ele,o=t.style,i=t.attr,a=t.parent,c=r instanceof HTMLElement?r:document.createElement(null!=r?r:"div");return o&&(null===(e=Object.keys(o))||void 0===e||e.forEach((function(t){return c.style[t]=o[t]}))),i&&(null===(n=Object.keys(i))||void 0===n||n.forEach((function(t){return c[t]=i[t]}))),a&&a.appendChild(c),c},H={createElement:z},K=function(t,e,n){t.addEventListener?t.addEventListener(e,n,!1):t["on"+e]=n},P=function(t){(t=t||window.event).stopPropagation?t.stopPropagation():t.cancelBubble=!1},_=function(t){(t=t||window.event).preventDefault?t.preventDefault():t.returnValue=!1},C=function(t,e,n){if(t.removeEventListener)t.removeEventListener(e,n,!1);else{var r="on"+e;"function"==typeof t[r]&&(t[r]=function(){})}},W=function(t,e){var n=new Event(e);t.dispatchEvent(n)},U={addHandler:K,stopBubble:P,stopDefault:_,removeHandler:C,dispatchEvent:W},Z=function(t,e){try{localStorage.setItem(t,JSON.stringify(e))}catch(t){console.error(t)}},G=function(t){try{var e=localStorage.getItem(t);return null==e?null:JSON.parse(e)}catch(t){return console.error(t),null}},Q=function(t){try{t&&localStorage.removeItem(t),!t&&localStorage.clear()}catch(t){console.error(t)}},X={setStorage:Z,getStorage:G,clearStorage:Q},Y=function(t,e,n){void 0===e&&(e=!1),void 0===n&&(n=!0),e&&(process.stdout.clearLine(0),process.stdout.cursorTo(0)),process.stdout.write(t),n&&process.stdout.write("\n")},$=function(t){return Y(t,!0,!1)},tt=["\\","|","/","—","—"],et=function(t){var e;void 0===t&&(t={});var n=t.loopList,r=void 0===n?tt:n,o=t.isStop,i=void 0!==o&&o,a=t.timer,c=void 0===a?100:a,u=t.index,l=void 0===u?0:u,s=null!==(e=null==r?void 0:r.length)&&void 0!==e?e:0;if(!s)return t;if(i)return $("\n");l>=s-1&&(l=0);var f=r[l++];return $(f),setTimeout((function(){t.index=l,et(t)}),c),t},nt={logOneLine:Y,logLoop:et},rt=function(){function t(t){this.fn=t,this.id=null,this.duration=1/0,this.isActive=!1}return t.prototype.start=function(t){if(!this.isActive)return this.duration=null!=t?t:1/0,this.isActive=!0,this.animate()},t.prototype.stop=function(t){void 0===t&&(t=this.id),this.isActive=!1,cancelAnimationFrame(t)},t.prototype.animate=function(t){if(void 0===t&&(t=0),this.isActive&&this.duration-- >0)return this.fn(t),this.id=requestAnimationFrame(this.animate.bind(this)),this.id},t}();function ot(t,e,n){var r=1-n,o=n*n;return[2*r*n*t+o,2*r*n*e+o]}function it(t,e,n,r,o){var i=3*t,a=3*e,c=3*(n-t)-i,u=3*(r-e)-a,l=1-a-u;return[(1-i-c)*Math.pow(o,3)+c*Math.pow(o,2)+i*o,l*Math.pow(o,3)+u*Math.pow(o,2)+a*o]}function at(t){return 0===t||1===t?1:t*at(t-1)}function ct(t,e){return at(t)/(at(e)*at(t-e))}function ut(t,e){for(var n=t.length-1,r=[0,0],o=0;o<=n;o++){var i=ct(n,o)*Math.pow(1-e,n-o)*Math.pow(e,o);r[0]+=i*t[o][0],r[1]+=i*t[o][1]}return r}var lt={AnimateFrame:rt,quadraticBezier:ot,cubicBezier:it,factorial:at,combination:ct,NBezier:ut},st=n(n(n(n(n(n(n(n(n(n({},T),f),k),V),H),o),U),X),nt),lt);return t.AnimateFrame=rt,t.NBezier=ut,t.addHandler=K,t.arrayDemote=I,t.arrayLoop=N,t.arrayRandom=D,t.arrayUniq=B,t.catchAwait=F,t.classDecorator=E,t.clearStorage=Q,t.cloneDeep=m,t.combination=ct,t.createElement=z,t.createObject=g,t.createObjectVariable=b,t.cubicBezier=it,t.debounce=R,t.default=st,t.defer=q,t.dispatchEvent=W,t.emptyObject=L,t.enumInversion=h,t.factorial=at,t.getInstance=j,t.getStorage=G,t.getType=u,t.getTypeByList=l,t.getValue=p,t.inherit=w,t.isEmptyObject=M,t.isNotObject=y,t.isWindow=A,t.jsonToString=S,t.logLoop=et,t.logOneLine=Y,t.mixIn=d,t.quadraticBezier=ot,t.randomNum=i,t.removeHandler=C,t.requestFrame=function(t,e){if(void 0===e&&(e=0),!t)throw Error("callback is empty");var n="undefined"!=typeof process?setImmediate:requestAnimationFrame,r=performance,o=r.now(),i=!1,a=function(){i||(r.now()-o>=e&&(o=r.now(),t(o)),n(a))};return a(),function(){return i=!0}},t.setStorage=Z,t.setValue=v,t.stopBubble=P,t.stopDefault=_,t.stringToJson=O,t.throttle=J,t.toKebabCase=s,t.urlJoin=c,t.urlSplit=a,Object.defineProperty(t,"__esModule",{value:!0}),t}({});
1
+ var UtilsLib=function(t){"use strict";var e,n=function(){return n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function r(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}t.types=void 0,(e=t.types||(t.types={}))["[object Array]"]="array",e["[object Object]"]="object",e["[object Function]"]="function",e["[object Set]"]="set",e["[object Map]"]="map",e["[object WeakMap]"]="weakMap",e["[object WeakSet]"]="weakSet",e["[object Date]"]="date",e["[object RegExp]"]="regExp",e["[object Math]"]="math";var o={types:t.types},i=function(t,e,n){return void 0===n&&(n=!1),Math.floor(Math.random()*(e-t+(n?1:0))+t)},a=function(t){var e={};return t.includes("?")?(t.split("?")[1].split("&").forEach((function(t){var n=t.split("=")[0];e[n]=t.split("=")[1]})),e):e},c=function(t,e){void 0===e&&(e={});var n=Object.keys(e);if(0===n.length)return t;var r=n.map((function(t){return"".concat(t,"=").concat(e[t])}));return"".concat(t).concat(t.includes("?")?"&":"?").concat(r.join("&"))},u=function(e){var n=typeof e;if(null===e)return"null";if("object"===n){var r=Object.prototype.toString.call(e);return t.types[r]}return n},l=function(t,e){void 0===e&&(e=[]);var n=u(t);return e.includes(n)},s=function(t,e){return void 0===e&&(e="-"),t.replace(/[A-Z]/g,(function(t){return"".concat(e).concat(t.toLowerCase())}))},f={randomNum:i,urlSplit:a,urlJoin:c,getType:u,getTypeByList:l,toKebabCase:s},p=function(t,e,n){void 0===n&&(n="");for(var r=0,o=e.split(".");r<o.length;r++){if(void 0===(t=t[o[r]]))return n}return t},v=function(t,e,n){void 0===n&&(n={});for(var r=e.split("."),o=r[r.length-1],i=t,a=0,c=r;a<c.length;a++){var u=c[a];if("object"!=typeof i&&void 0!==i)return t;!i&&(i={}),!i[u]&&(i[u]={}),o===u&&(i[o]=n),i=i[u]}return t},d=function(t,e,n){var r;for(var o in void 0===e&&(e={}),void 0===n&&(n=!1),e)for(var i in e[o]){var a=null!==(r=null==t?void 0:t.prototype)&&void 0!==r?r:t;(void 0===(null==t?void 0:t[i])||n)&&(a[i]=e[o][i])}return t},y=function(t){for(var e in t){var n=t[e];"string"!=typeof n||t[n]||(t[n]=e)}return t},h=function(t,e){return"object"!=typeof t||"null"===e},m=function(t){var e=u(t);if(h(t,e))return t;var n=b(e,t);return"map"===e?t.forEach((function(t,e){n.set(e,m(t))})):"set"===e?t.forEach((function(t){n.add(m(t))})):Reflect.ownKeys(t).forEach((function(e){var r=t[e];n[e]=m(r)})),n},b=function(t,e){switch(void 0===e&&(e={}),t){case"array":return[];case"function":return e;case"set":return new Set;case"map":return new Map;case"date":return new Date(e);case"regExp":return new RegExp(e);case"math":return Math;default:return{}}},g=function(t){function e(){}return e.prototype=t,new e},w=function(t,e){return void 0===e&&(e=function(){}),e.prototype=g(t.prototype),e.prototype.super=t,e.prototype.constructor=e,e},j=function(t,e){void 0===e&&(e=!1);for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];return t._instance&&!e||(t._instance=new(t.bind.apply(t,r([void 0],n,!1)))),t._instance},E=function(t){return function(e){for(var n in t)Reflect.has(e.prototype,n)||(e.prototype[n]=t[n])}},O=function(t){if("string"!==u(t))return null;try{return JSON.parse(t)}catch(t){return null}},S=function(t){if(!l(t,["array","object","set","map"]))return"";try{return JSON.stringify(t)}catch(t){return""}},A=function(t){return t&&t===t.window},L=function(t){void 0===t&&(t={});var e=Object.create(null);return Reflect.ownKeys(t).forEach((function(n){return e[n]=t[n]})),e},M=function(t){void 0===t&&(t={});var e=L(t);return Reflect.ownKeys(e).length<=0},T={getValue:p,setValue:v,mixIn:d,enumInversion:y,isNotObject:h,cloneDeep:m,createObjectVariable:b,createObject:g,inherit:w,getInstance:j,classDecorator:E,stringToJson:O,jsonToString:S,isWindow:A,emptyObject:L,isEmptyObject:M},D=function(t){return t.sort((function(){return Math.random()-.5}))},B=function(t){return Array.from(new Set(t))},I=function(t,e){return void 0===e&&(e=[]),t.forEach((function(t){return"array"===u(t)?I(t,e):e.push(t)})),e},N=function(t,e){return void 0===e&&(e=0),{item:t[e],current:(e+1)%t.length}},k={arrayRandom:D,arrayUniq:B,arrayDemote:I,arrayLoop:N},x=void 0,J=function(t,e){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n||(n=setTimeout((function(){t.call.apply(t,r([x],o,!1)),n=null}),e))}},R=function(t,e){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n&&(clearTimeout(n),n=null),n=setTimeout((function(){t.call.apply(t,r([x],o,!1))}),e)}},q=function(t){var e,n;return void 0===t&&(t=0),{promise:new Promise((function(r,o){e=r,n=o,t>0&&setTimeout((function(){return n("timeout")}),t)})),resolve:e,reject:n}},F=function(t){return t?t.then((function(t){return[null,t]})).catch((function(t){return[t]})):[new Error("defer is empty")]},V={throttle:J,debounce:R,defer:q,catchAwait:F},z=function(t){var e,n,r=t.ele,o=t.style,i=t.attr,a=t.parent,c=r instanceof HTMLElement?r:document.createElement(null!=r?r:"div");return o&&(null===(e=Object.keys(o))||void 0===e||e.forEach((function(t){return c.style[t]=o[t]}))),i&&(null===(n=Object.keys(i))||void 0===n||n.forEach((function(t){return c[t]=i[t]}))),a&&a.appendChild(c),c},H={createElement:z},K=function(t,e,n){t.addEventListener?t.addEventListener(e,n,!1):t["on"+e]=n},P=function(t){(t=t||window.event).stopPropagation?t.stopPropagation():t.cancelBubble=!1},_=function(t){(t=t||window.event).preventDefault?t.preventDefault():t.returnValue=!1},C=function(t,e,n){if(t.removeEventListener)t.removeEventListener(e,n,!1);else{var r="on"+e;"function"==typeof t[r]&&(t[r]=function(){})}},W=function(t,e){var n=new Event(e);t.dispatchEvent(n)},U={addHandler:K,stopBubble:P,stopDefault:_,removeHandler:C,dispatchEvent:W},Z=function(t,e){try{localStorage.setItem(t,JSON.stringify(e))}catch(t){console.error(t)}},G=function(t){try{var e=localStorage.getItem(t);return null==e?null:JSON.parse(e)}catch(t){return console.error(t),null}},Q=function(t){try{t&&localStorage.removeItem(t),!t&&localStorage.clear()}catch(t){console.error(t)}},X={setStorage:Z,getStorage:G,clearStorage:Q},Y=function(t,e,n){void 0===e&&(e=!1),void 0===n&&(n=!0),e&&(process.stdout.clearLine(0),process.stdout.cursorTo(0)),process.stdout.write(t),n&&process.stdout.write("\n")},$=function(t){return Y(t,!0,!1)},tt=["\\","|","/","—","—"],et=function(t){var e;void 0===t&&(t={});var n=t.loopList,r=void 0===n?tt:n,o=t.isStop,i=void 0!==o&&o,a=t.timer,c=void 0===a?100:a,u=t.index,l=void 0===u?0:u,s=null!==(e=null==r?void 0:r.length)&&void 0!==e?e:0;if(!s)return t;if(i)return $("\n");l>=s-1&&(l=0);var f=r[l++];return $(f),setTimeout((function(){t.index=l,et(t)}),c),t},nt={logOneLine:Y,logLoop:et},rt=function(){function t(t){this.fn=t,this.id=null,this.duration=1/0,this.isActive=!1}return t.prototype.start=function(t){if(!this.isActive)return this.duration=null!=t?t:1/0,this.isActive=!0,this.animate()},t.prototype.stop=function(t){void 0===t&&(t=this.id),this.isActive=!1,cancelAnimationFrame(t)},t.prototype.animate=function(t){if(void 0===t&&(t=0),this.isActive&&this.duration-- >0)return this.fn(t),this.id=requestAnimationFrame(this.animate.bind(this)),this.id},t}();function ot(t,e,n){var r=1-n,o=n*n;return[2*r*n*t+o,2*r*n*e+o]}function it(t,e,n,r,o){var i=3*t,a=3*e,c=3*(n-t)-i,u=3*(r-e)-a,l=1-a-u;return[(1-i-c)*Math.pow(o,3)+c*Math.pow(o,2)+i*o,l*Math.pow(o,3)+u*Math.pow(o,2)+a*o]}function at(t){return 0===t||1===t?1:t*at(t-1)}function ct(t,e){return at(t)/(at(e)*at(t-e))}function ut(t,e){for(var n=t.length-1,r=[0,0],o=0;o<=n;o++){var i=ct(n,o)*Math.pow(1-e,n-o)*Math.pow(e,o);r[0]+=i*t[o][0],r[1]+=i*t[o][1]}return r}var lt={AnimateFrame:rt,quadraticBezier:ot,cubicBezier:it,factorial:at,combination:ct,NBezier:ut},st=n(n(n(n(n(n(n(n(n(n({},T),f),k),V),H),o),U),X),nt),lt);return t.AnimateFrame=rt,t.NBezier=ut,t.addHandler=K,t.arrayDemote=I,t.arrayLoop=N,t.arrayRandom=D,t.arrayUniq=B,t.catchAwait=F,t.classDecorator=E,t.clearStorage=Q,t.cloneDeep=m,t.combination=ct,t.createElement=z,t.createObject=g,t.createObjectVariable=b,t.cubicBezier=it,t.debounce=R,t.default=st,t.defer=q,t.dispatchEvent=W,t.emptyObject=L,t.enumInversion=y,t.factorial=at,t.getInstance=j,t.getStorage=G,t.getType=u,t.getTypeByList=l,t.getValue=p,t.inherit=w,t.isEmptyObject=M,t.isNotObject=h,t.isWindow=A,t.jsonToString=S,t.logLoop=et,t.logOneLine=Y,t.mixIn=d,t.quadraticBezier=ot,t.randomNum=i,t.removeHandler=C,t.requestFrame=function(t,e){if(void 0===e&&(e=0),!t)throw Error("callback is empty");var n="undefined"!=typeof process?setImmediate:requestAnimationFrame,r=performance,o=r.now(),i=!1,a=function(){i||(r.now()-o>=e&&(o=r.now(),t(o)),n(a))};return a(),function(){return i=!0}},t.setStorage=Z,t.setValue=v,t.stopBubble=P,t.stopDefault=_,t.stringToJson=O,t.throttle=J,t.toKebabCase=s,t.urlJoin=c,t.urlSplit=a,Object.defineProperty(t,"__esModule",{value:!0}),t}({});
@@ -1,9 +1,9 @@
1
1
  export type IKey = string | symbol | number;
2
2
  export type IObject<V = any, K extends string | number | symbol = IKey> = Record<K, V>;
3
- export interface IPromise extends IObject<any> {
4
- promise?: Promise<void>;
5
- resolve?: (res?: any) => unknown;
6
- reject?: (err?: any) => unknown;
3
+ export interface IPromise<T = any> {
4
+ promise: Promise<T>;
5
+ resolve: (res?: T) => unknown;
6
+ reject: (err?: any) => unknown;
7
7
  }
8
8
  export type IInstance<T> = {
9
9
  _instance: Function;
@@ -28,8 +28,8 @@ export type IStringToJson = (target: string) => IObject<any> | null;
28
28
  export type IJsonToString = (target: IObject<any>) => string;
29
29
  export type IThrottle = (fn: Function, time: number) => (...args: any[]) => void;
30
30
  export type IDebounce = (fn: Function, time: number) => (...args: any[]) => void;
31
- export type IDefer = (timer?: number) => IPromise;
32
- export type ICatchAwait<T extends Promise<any>> = (defer: T) => T;
31
+ export type IDefer = <T>(timer?: number) => IPromise<T>;
32
+ export type ICatchAwait<T extends Promise<any>> = (defer?: T) => T | [Error];
33
33
  export type IRequestFrame = (callback: (start: number) => void, delay: number) => () => void;
34
34
  export type IArrayRandom<T extends any[]> = (arr: T) => T;
35
35
  export type IArrayUniq<T extends any[]> = (arr: T) => T;
@@ -1,4 +1,4 @@
1
- import { ICatchAwait, IThrottle, IDebounce, IDefer, IRequestFrame } from "./types";
1
+ import { ICatchAwait, IDebounce, IDefer, IRequestFrame, IThrottle } from "./types";
2
2
  export declare const throttle: IThrottle;
3
3
  export declare const debounce: IDebounce;
4
4
  export declare const defer: IDefer;
package/dist/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=function(){return e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},e.apply(this,arguments)};function r(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}exports.types=void 0,(t=exports.types||(exports.types={}))["[object Array]"]="array",t["[object Object]"]="object",t["[object Function]"]="function",t["[object Set]"]="set",t["[object Map]"]="map",t["[object WeakMap]"]="weakMap",t["[object WeakSet]"]="weakSet",t["[object Date]"]="date",t["[object RegExp]"]="regExp",t["[object Math]"]="math";var n={types:exports.types},o=function(t,e,r){return void 0===r&&(r=!1),Math.floor(Math.random()*(e-t+(r?1:0))+t)},i=function(t){var e={};return t.includes("?")?(t.split("?")[1].split("&").forEach((function(t){var r=t.split("=")[0];e[r]=t.split("=")[1]})),e):e},a=function(t,e){void 0===e&&(e={});var r=Object.keys(e);if(0===r.length)return t;var n=r.map((function(t){return"".concat(t,"=").concat(e[t])}));return"".concat(t).concat(t.includes("?")?"&":"?").concat(n.join("&"))},c=function(t){var e=typeof t;if(null===t)return"null";if("object"===e){var r=Object.prototype.toString.call(t);return exports.types[r]}return e},u=function(t,e){void 0===e&&(e=[]);var r=c(t);return e.includes(r)},s=function(t,e){return void 0===e&&(e="-"),t.replace(/[A-Z]/g,(function(t){return"".concat(e).concat(t.toLowerCase())}))},p={randomNum:o,urlSplit:i,urlJoin:a,getType:c,getTypeByList:u,toKebabCase:s},l=function(t,e,r){void 0===r&&(r="");for(var n=0,o=e.split(".");n<o.length;n++){if(void 0===(t=t[o[n]]))return r}return t},f=function(t,e,r){void 0===r&&(r={});for(var n=e.split("."),o=n[n.length-1],i=t,a=0,c=n;a<c.length;a++){var u=c[a];if("object"!=typeof i&&void 0!==i)return t;!i&&(i={}),!i[u]&&(i[u]={}),o===u&&(i[o]=r),i=i[u]}return t},v=function(t,e,r){var n;for(var o in void 0===e&&(e={}),void 0===r&&(r=!1),e)for(var i in e[o]){var a=null!==(n=null==t?void 0:t.prototype)&&void 0!==n?n:t;(void 0===(null==t?void 0:t[i])||r)&&(a[i]=e[o][i])}return t},d=function(t){for(var e in t){var r=t[e];"string"!=typeof r||t[r]||(t[r]=e)}return t},h=function(t,e){return"object"!=typeof t||"null"===e},y=function(t){var e=c(t);if(h(t,e))return t;var r=m(e,t);return"map"===e?t.forEach((function(t,e){r.set(e,y(t))})):"set"===e?t.forEach((function(t){r.add(y(t))})):Reflect.ownKeys(t).forEach((function(e){var n=t[e];r[e]=y(n)})),r},m=function(t,e){switch(void 0===e&&(e={}),t){case"array":return[];case"function":return e;case"set":return new Set;case"map":return new Map;case"date":return new Date(e);case"regExp":return new RegExp(e);case"math":return Math;default:return{}}},x=function(t){function e(){}return e.prototype=t,new e},g=function(t,e){return void 0===e&&(e=function(){}),e.prototype=x(t.prototype),e.prototype.super=t,e.prototype.constructor=e,e},b=function(t,e){void 0===e&&(e=!1);for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];return t._instance&&!e||(t._instance=new(t.bind.apply(t,r([void 0],n,!1)))),t._instance},w=function(t){return function(e){for(var r in t)Reflect.has(e.prototype,r)||(e.prototype[r]=t[r])}},j=function(t){if("string"!==c(t))return null;try{return JSON.parse(t)}catch(t){return null}},E=function(t){if(!u(t,["array","object","set","map"]))return"";try{return JSON.stringify(t)}catch(t){return""}},O=function(t){return t&&t===t.window},S=function(t){void 0===t&&(t={});var e=Object.create(null);return Reflect.ownKeys(t).forEach((function(r){return e[r]=t[r]})),e},A=function(t){void 0===t&&(t={});var e=S(t);return Reflect.ownKeys(e).length<=0},M={getValue:l,setValue:f,mixIn:v,enumInversion:d,isNotObject:h,cloneDeep:y,createObjectVariable:m,createObject:x,inherit:g,getInstance:b,classDecorator:w,stringToJson:j,jsonToString:E,isWindow:O,emptyObject:S,isEmptyObject:A},L=function(t){return t.sort((function(){return Math.random()-.5}))},T=function(t){return Array.from(new Set(t))},D=function(t,e){return void 0===e&&(e=[]),t.forEach((function(t){return"array"===c(t)?D(t,e):e.push(t)})),e},B=function(t,e){return void 0===e&&(e=0),{item:t[e],current:(e+1)%t.length}},I={arrayRandom:L,arrayUniq:T,arrayDemote:D,arrayLoop:B},N=void 0,k=function(t,e){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n||(n=setTimeout((function(){t.call.apply(t,r([N],o,!1)),n=null}),e))}},J=function(t,e){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n&&(clearTimeout(n),n=null),n=setTimeout((function(){t.call.apply(t,r([N],o,!1))}),e)}},R=function(t){var e,r;return void 0===t&&(t=0),{promise:new Promise((function(n,o){e=n,r=o,t>0&&setTimeout((function(){return r("timeout")}),t)})),resolve:e,reject:r}},q=function(t){return t.then((function(t){return[null,t]})).catch((function(t){return[t]}))},F={throttle:k,debounce:J,defer:R,catchAwait:q},V=function(t){var e,r,n=t.ele,o=t.style,i=t.attr,a=t.parent,c=n instanceof HTMLElement?n:document.createElement(null!=n?n:"div");return o&&(null===(e=Object.keys(o))||void 0===e||e.forEach((function(t){return c.style[t]=o[t]}))),i&&(null===(r=Object.keys(i))||void 0===r||r.forEach((function(t){return c[t]=i[t]}))),a&&a.appendChild(c),c},z={createElement:V},H=function(t,e,r){t.addEventListener?t.addEventListener(e,r,!1):t["on"+e]=r},K=function(t){(t=t||window.event).stopPropagation?t.stopPropagation():t.cancelBubble=!1},P=function(t){(t=t||window.event).preventDefault?t.preventDefault():t.returnValue=!1},_=function(t,e,r){if(t.removeEventListener)t.removeEventListener(e,r,!1);else{var n="on"+e;"function"==typeof t[n]&&(t[n]=function(){})}},C=function(t,e){var r=new Event(e);t.dispatchEvent(r)},W={addHandler:H,stopBubble:K,stopDefault:P,removeHandler:_,dispatchEvent:C},U=function(t,e){try{localStorage.setItem(t,JSON.stringify(e))}catch(t){console.error(t)}},Z=function(t){try{var e=localStorage.getItem(t);return null==e?null:JSON.parse(e)}catch(t){return console.error(t),null}},G=function(t){try{t&&localStorage.removeItem(t),!t&&localStorage.clear()}catch(t){console.error(t)}},Q={setStorage:U,getStorage:Z,clearStorage:G},X=function(t,e,r){void 0===e&&(e=!1),void 0===r&&(r=!0),e&&(process.stdout.clearLine(0),process.stdout.cursorTo(0)),process.stdout.write(t),r&&process.stdout.write("\n")},Y=function(t){return X(t,!0,!1)},$=["\\","|","/","—","—"],tt=function(t){var e;void 0===t&&(t={});var r=t.loopList,n=void 0===r?$:r,o=t.isStop,i=void 0!==o&&o,a=t.timer,c=void 0===a?100:a,u=t.index,s=void 0===u?0:u,p=null!==(e=null==n?void 0:n.length)&&void 0!==e?e:0;if(!p)return t;if(i)return Y("\n");s>=p-1&&(s=0);var l=n[s++];return Y(l),setTimeout((function(){t.index=s,tt(t)}),c),t},et={logOneLine:X,logLoop:tt},rt=function(){function t(t){this.fn=t,this.id=null,this.duration=1/0,this.isActive=!1}return t.prototype.start=function(t){if(!this.isActive)return this.duration=null!=t?t:1/0,this.isActive=!0,this.animate()},t.prototype.stop=function(t){void 0===t&&(t=this.id),this.isActive=!1,cancelAnimationFrame(t)},t.prototype.animate=function(t){if(void 0===t&&(t=0),this.isActive&&this.duration-- >0)return this.fn(t),this.id=requestAnimationFrame(this.animate.bind(this)),this.id},t}();function nt(t,e,r){var n=1-r,o=r*r;return[2*n*r*t+o,2*n*r*e+o]}function ot(t,e,r,n,o){var i=3*t,a=3*e,c=3*(r-t)-i,u=3*(n-e)-a,s=1-a-u;return[(1-i-c)*Math.pow(o,3)+c*Math.pow(o,2)+i*o,s*Math.pow(o,3)+u*Math.pow(o,2)+a*o]}function it(t){return 0===t||1===t?1:t*it(t-1)}function at(t,e){return it(t)/(it(e)*it(t-e))}function ct(t,e){for(var r=t.length-1,n=[0,0],o=0;o<=r;o++){var i=at(r,o)*Math.pow(1-e,r-o)*Math.pow(e,o);n[0]+=i*t[o][0],n[1]+=i*t[o][1]}return n}var ut={AnimateFrame:rt,quadraticBezier:nt,cubicBezier:ot,factorial:it,combination:at,NBezier:ct},st=e(e(e(e(e(e(e(e(e(e({},M),p),I),F),z),n),W),Q),et),ut);exports.AnimateFrame=rt,exports.NBezier=ct,exports.addHandler=H,exports.arrayDemote=D,exports.arrayLoop=B,exports.arrayRandom=L,exports.arrayUniq=T,exports.catchAwait=q,exports.classDecorator=w,exports.clearStorage=G,exports.cloneDeep=y,exports.combination=at,exports.createElement=V,exports.createObject=x,exports.createObjectVariable=m,exports.cubicBezier=ot,exports.debounce=J,exports.default=st,exports.defer=R,exports.dispatchEvent=C,exports.emptyObject=S,exports.enumInversion=d,exports.factorial=it,exports.getInstance=b,exports.getStorage=Z,exports.getType=c,exports.getTypeByList=u,exports.getValue=l,exports.inherit=g,exports.isEmptyObject=A,exports.isNotObject=h,exports.isWindow=O,exports.jsonToString=E,exports.logLoop=tt,exports.logOneLine=X,exports.mixIn=v,exports.quadraticBezier=nt,exports.randomNum=o,exports.removeHandler=_,exports.requestFrame=function(t,e){if(void 0===e&&(e=0),!t)throw Error("callback is empty");var r="undefined"!=typeof process?setImmediate:requestAnimationFrame,n=performance,o=n.now(),i=!1,a=function(){i||(n.now()-o>=e&&(o=n.now(),t(o)),r(a))};return a(),function(){return i=!0}},exports.setStorage=U,exports.setValue=f,exports.stopBubble=K,exports.stopDefault=P,exports.stringToJson=j,exports.throttle=k,exports.toKebabCase=s,exports.urlJoin=a,exports.urlSplit=i;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=function(){return e=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},e.apply(this,arguments)};function r(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}exports.types=void 0,(t=exports.types||(exports.types={}))["[object Array]"]="array",t["[object Object]"]="object",t["[object Function]"]="function",t["[object Set]"]="set",t["[object Map]"]="map",t["[object WeakMap]"]="weakMap",t["[object WeakSet]"]="weakSet",t["[object Date]"]="date",t["[object RegExp]"]="regExp",t["[object Math]"]="math";var n={types:exports.types},o=function(t,e,r){return void 0===r&&(r=!1),Math.floor(Math.random()*(e-t+(r?1:0))+t)},i=function(t){var e={};return t.includes("?")?(t.split("?")[1].split("&").forEach((function(t){var r=t.split("=")[0];e[r]=t.split("=")[1]})),e):e},a=function(t,e){void 0===e&&(e={});var r=Object.keys(e);if(0===r.length)return t;var n=r.map((function(t){return"".concat(t,"=").concat(e[t])}));return"".concat(t).concat(t.includes("?")?"&":"?").concat(n.join("&"))},c=function(t){var e=typeof t;if(null===t)return"null";if("object"===e){var r=Object.prototype.toString.call(t);return exports.types[r]}return e},u=function(t,e){void 0===e&&(e=[]);var r=c(t);return e.includes(r)},s=function(t,e){return void 0===e&&(e="-"),t.replace(/[A-Z]/g,(function(t){return"".concat(e).concat(t.toLowerCase())}))},p={randomNum:o,urlSplit:i,urlJoin:a,getType:c,getTypeByList:u,toKebabCase:s},l=function(t,e,r){void 0===r&&(r="");for(var n=0,o=e.split(".");n<o.length;n++){if(void 0===(t=t[o[n]]))return r}return t},f=function(t,e,r){void 0===r&&(r={});for(var n=e.split("."),o=n[n.length-1],i=t,a=0,c=n;a<c.length;a++){var u=c[a];if("object"!=typeof i&&void 0!==i)return t;!i&&(i={}),!i[u]&&(i[u]={}),o===u&&(i[o]=r),i=i[u]}return t},v=function(t,e,r){var n;for(var o in void 0===e&&(e={}),void 0===r&&(r=!1),e)for(var i in e[o]){var a=null!==(n=null==t?void 0:t.prototype)&&void 0!==n?n:t;(void 0===(null==t?void 0:t[i])||r)&&(a[i]=e[o][i])}return t},d=function(t){for(var e in t){var r=t[e];"string"!=typeof r||t[r]||(t[r]=e)}return t},y=function(t,e){return"object"!=typeof t||"null"===e},h=function(t){var e=c(t);if(y(t,e))return t;var r=m(e,t);return"map"===e?t.forEach((function(t,e){r.set(e,h(t))})):"set"===e?t.forEach((function(t){r.add(h(t))})):Reflect.ownKeys(t).forEach((function(e){var n=t[e];r[e]=h(n)})),r},m=function(t,e){switch(void 0===e&&(e={}),t){case"array":return[];case"function":return e;case"set":return new Set;case"map":return new Map;case"date":return new Date(e);case"regExp":return new RegExp(e);case"math":return Math;default:return{}}},x=function(t){function e(){}return e.prototype=t,new e},g=function(t,e){return void 0===e&&(e=function(){}),e.prototype=x(t.prototype),e.prototype.super=t,e.prototype.constructor=e,e},b=function(t,e){void 0===e&&(e=!1);for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];return t._instance&&!e||(t._instance=new(t.bind.apply(t,r([void 0],n,!1)))),t._instance},w=function(t){return function(e){for(var r in t)Reflect.has(e.prototype,r)||(e.prototype[r]=t[r])}},j=function(t){if("string"!==c(t))return null;try{return JSON.parse(t)}catch(t){return null}},E=function(t){if(!u(t,["array","object","set","map"]))return"";try{return JSON.stringify(t)}catch(t){return""}},O=function(t){return t&&t===t.window},S=function(t){void 0===t&&(t={});var e=Object.create(null);return Reflect.ownKeys(t).forEach((function(r){return e[r]=t[r]})),e},A=function(t){void 0===t&&(t={});var e=S(t);return Reflect.ownKeys(e).length<=0},M={getValue:l,setValue:f,mixIn:v,enumInversion:d,isNotObject:y,cloneDeep:h,createObjectVariable:m,createObject:x,inherit:g,getInstance:b,classDecorator:w,stringToJson:j,jsonToString:E,isWindow:O,emptyObject:S,isEmptyObject:A},L=function(t){return t.sort((function(){return Math.random()-.5}))},T=function(t){return Array.from(new Set(t))},D=function(t,e){return void 0===e&&(e=[]),t.forEach((function(t){return"array"===c(t)?D(t,e):e.push(t)})),e},B=function(t,e){return void 0===e&&(e=0),{item:t[e],current:(e+1)%t.length}},I={arrayRandom:L,arrayUniq:T,arrayDemote:D,arrayLoop:B},N=void 0,k=function(t,e){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n||(n=setTimeout((function(){t.call.apply(t,r([N],o,!1)),n=null}),e))}},J=function(t,e){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n&&(clearTimeout(n),n=null),n=setTimeout((function(){t.call.apply(t,r([N],o,!1))}),e)}},R=function(t){var e,r;return void 0===t&&(t=0),{promise:new Promise((function(n,o){e=n,r=o,t>0&&setTimeout((function(){return r("timeout")}),t)})),resolve:e,reject:r}},q=function(t){return t?t.then((function(t){return[null,t]})).catch((function(t){return[t]})):[new Error("defer is empty")]},F={throttle:k,debounce:J,defer:R,catchAwait:q},V=function(t){var e,r,n=t.ele,o=t.style,i=t.attr,a=t.parent,c=n instanceof HTMLElement?n:document.createElement(null!=n?n:"div");return o&&(null===(e=Object.keys(o))||void 0===e||e.forEach((function(t){return c.style[t]=o[t]}))),i&&(null===(r=Object.keys(i))||void 0===r||r.forEach((function(t){return c[t]=i[t]}))),a&&a.appendChild(c),c},z={createElement:V},H=function(t,e,r){t.addEventListener?t.addEventListener(e,r,!1):t["on"+e]=r},K=function(t){(t=t||window.event).stopPropagation?t.stopPropagation():t.cancelBubble=!1},P=function(t){(t=t||window.event).preventDefault?t.preventDefault():t.returnValue=!1},_=function(t,e,r){if(t.removeEventListener)t.removeEventListener(e,r,!1);else{var n="on"+e;"function"==typeof t[n]&&(t[n]=function(){})}},C=function(t,e){var r=new Event(e);t.dispatchEvent(r)},W={addHandler:H,stopBubble:K,stopDefault:P,removeHandler:_,dispatchEvent:C},U=function(t,e){try{localStorage.setItem(t,JSON.stringify(e))}catch(t){console.error(t)}},Z=function(t){try{var e=localStorage.getItem(t);return null==e?null:JSON.parse(e)}catch(t){return console.error(t),null}},G=function(t){try{t&&localStorage.removeItem(t),!t&&localStorage.clear()}catch(t){console.error(t)}},Q={setStorage:U,getStorage:Z,clearStorage:G},X=function(t,e,r){void 0===e&&(e=!1),void 0===r&&(r=!0),e&&(process.stdout.clearLine(0),process.stdout.cursorTo(0)),process.stdout.write(t),r&&process.stdout.write("\n")},Y=function(t){return X(t,!0,!1)},$=["\\","|","/","—","—"],tt=function(t){var e;void 0===t&&(t={});var r=t.loopList,n=void 0===r?$:r,o=t.isStop,i=void 0!==o&&o,a=t.timer,c=void 0===a?100:a,u=t.index,s=void 0===u?0:u,p=null!==(e=null==n?void 0:n.length)&&void 0!==e?e:0;if(!p)return t;if(i)return Y("\n");s>=p-1&&(s=0);var l=n[s++];return Y(l),setTimeout((function(){t.index=s,tt(t)}),c),t},et={logOneLine:X,logLoop:tt},rt=function(){function t(t){this.fn=t,this.id=null,this.duration=1/0,this.isActive=!1}return t.prototype.start=function(t){if(!this.isActive)return this.duration=null!=t?t:1/0,this.isActive=!0,this.animate()},t.prototype.stop=function(t){void 0===t&&(t=this.id),this.isActive=!1,cancelAnimationFrame(t)},t.prototype.animate=function(t){if(void 0===t&&(t=0),this.isActive&&this.duration-- >0)return this.fn(t),this.id=requestAnimationFrame(this.animate.bind(this)),this.id},t}();function nt(t,e,r){var n=1-r,o=r*r;return[2*n*r*t+o,2*n*r*e+o]}function ot(t,e,r,n,o){var i=3*t,a=3*e,c=3*(r-t)-i,u=3*(n-e)-a,s=1-a-u;return[(1-i-c)*Math.pow(o,3)+c*Math.pow(o,2)+i*o,s*Math.pow(o,3)+u*Math.pow(o,2)+a*o]}function it(t){return 0===t||1===t?1:t*it(t-1)}function at(t,e){return it(t)/(it(e)*it(t-e))}function ct(t,e){for(var r=t.length-1,n=[0,0],o=0;o<=r;o++){var i=at(r,o)*Math.pow(1-e,r-o)*Math.pow(e,o);n[0]+=i*t[o][0],n[1]+=i*t[o][1]}return n}var ut={AnimateFrame:rt,quadraticBezier:nt,cubicBezier:ot,factorial:it,combination:at,NBezier:ct},st=e(e(e(e(e(e(e(e(e(e({},M),p),I),F),z),n),W),Q),et),ut);exports.AnimateFrame=rt,exports.NBezier=ct,exports.addHandler=H,exports.arrayDemote=D,exports.arrayLoop=B,exports.arrayRandom=L,exports.arrayUniq=T,exports.catchAwait=q,exports.classDecorator=w,exports.clearStorage=G,exports.cloneDeep=h,exports.combination=at,exports.createElement=V,exports.createObject=x,exports.createObjectVariable=m,exports.cubicBezier=ot,exports.debounce=J,exports.default=st,exports.defer=R,exports.dispatchEvent=C,exports.emptyObject=S,exports.enumInversion=d,exports.factorial=it,exports.getInstance=b,exports.getStorage=Z,exports.getType=c,exports.getTypeByList=u,exports.getValue=l,exports.inherit=g,exports.isEmptyObject=A,exports.isNotObject=y,exports.isWindow=O,exports.jsonToString=E,exports.logLoop=tt,exports.logOneLine=X,exports.mixIn=v,exports.quadraticBezier=nt,exports.randomNum=o,exports.removeHandler=_,exports.requestFrame=function(t,e){if(void 0===e&&(e=0),!t)throw Error("callback is empty");var r="undefined"!=typeof process?setImmediate:requestAnimationFrame,n=performance,o=n.now(),i=!1,a=function(){i||(n.now()-o>=e&&(o=n.now(),t(o)),r(a))};return a(),function(){return i=!0}},exports.setStorage=U,exports.setValue=f,exports.stopBubble=K,exports.stopDefault=P,exports.stringToJson=j,exports.throttle=k,exports.toKebabCase=s,exports.urlJoin=a,exports.urlSplit=i;
@@ -1,9 +1,9 @@
1
1
  export type IKey = string | symbol | number;
2
2
  export type IObject<V = any, K extends string | number | symbol = IKey> = Record<K, V>;
3
- export interface IPromise extends IObject<any> {
4
- promise?: Promise<void>;
5
- resolve?: (res?: any) => unknown;
6
- reject?: (err?: any) => unknown;
3
+ export interface IPromise<T = any> {
4
+ promise: Promise<T>;
5
+ resolve: (res?: T) => unknown;
6
+ reject: (err?: any) => unknown;
7
7
  }
8
8
  export type IInstance<T> = {
9
9
  _instance: Function;
@@ -28,8 +28,8 @@ export type IStringToJson = (target: string) => IObject<any> | null;
28
28
  export type IJsonToString = (target: IObject<any>) => string;
29
29
  export type IThrottle = (fn: Function, time: number) => (...args: any[]) => void;
30
30
  export type IDebounce = (fn: Function, time: number) => (...args: any[]) => void;
31
- export type IDefer = (timer?: number) => IPromise;
32
- export type ICatchAwait<T extends Promise<any>> = (defer: T) => T;
31
+ export type IDefer = <T>(timer?: number) => IPromise<T>;
32
+ export type ICatchAwait<T extends Promise<any>> = (defer?: T) => T | [Error];
33
33
  export type IRequestFrame = (callback: (start: number) => void, delay: number) => () => void;
34
34
  export type IArrayRandom<T extends any[]> = (arr: T) => T;
35
35
  export type IArrayUniq<T extends any[]> = (arr: T) => T;
@@ -1,4 +1,4 @@
1
- import { ICatchAwait, IThrottle, IDebounce, IDefer, IRequestFrame } from "./types";
1
+ import { ICatchAwait, IDebounce, IDefer, IRequestFrame, IThrottle } from "./types";
2
2
  export declare const throttle: IThrottle;
3
3
  export declare const debounce: IDebounce;
4
4
  export declare const defer: IDefer;
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- var t,n=function(){return n=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},n.apply(this,arguments)};function e(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))}!function(t){t["[object Array]"]="array",t["[object Object]"]="object",t["[object Function]"]="function",t["[object Set]"]="set",t["[object Map]"]="map",t["[object WeakMap]"]="weakMap",t["[object WeakSet]"]="weakSet",t["[object Date]"]="date",t["[object RegExp]"]="regExp",t["[object Math]"]="math"}(t||(t={}));var r={types:t},o=function(t,n,e){return void 0===e&&(e=!1),Math.floor(Math.random()*(n-t+(e?1:0))+t)},i=function(t){var n={};return t.includes("?")?(t.split("?")[1].split("&").forEach((function(t){var e=t.split("=")[0];n[e]=t.split("=")[1]})),n):n},a=function(t,n){void 0===n&&(n={});var e=Object.keys(n);if(0===e.length)return t;var r=e.map((function(t){return"".concat(t,"=").concat(n[t])}));return"".concat(t).concat(t.includes("?")?"&":"?").concat(r.join("&"))},c=function(n){var e=typeof n;if(null===n)return"null";if("object"===e){var r=Object.prototype.toString.call(n);return t[r]}return e},u=function(t,n){void 0===n&&(n=[]);var e=c(t);return n.includes(e)},f=function(t,n){return void 0===n&&(n="-"),t.replace(/[A-Z]/g,(function(t){return"".concat(n).concat(t.toLowerCase())}))},l={randomNum:o,urlSplit:i,urlJoin:a,getType:c,getTypeByList:u,toKebabCase:f},s=function(t,n,e){void 0===e&&(e="");for(var r=0,o=n.split(".");r<o.length;r++){if(void 0===(t=t[o[r]]))return e}return t},p=function(t,n,e){void 0===e&&(e={});for(var r=n.split("."),o=r[r.length-1],i=t,a=0,c=r;a<c.length;a++){var u=c[a];if("object"!=typeof i&&void 0!==i)return t;!i&&(i={}),!i[u]&&(i[u]={}),o===u&&(i[o]=e),i=i[u]}return t},v=function(t,n,e){var r;for(var o in void 0===n&&(n={}),void 0===e&&(e=!1),n)for(var i in n[o]){var a=null!==(r=null==t?void 0:t.prototype)&&void 0!==r?r:t;(void 0===(null==t?void 0:t[i])||e)&&(a[i]=n[o][i])}return t},d=function(t){for(var n in t){var e=t[n];"string"!=typeof e||t[e]||(t[e]=n)}return t},h=function(t,n){return"object"!=typeof t||"null"===n},y=function(t){var n=c(t);if(h(t,n))return t;var e=m(n,t);return"map"===n?t.forEach((function(t,n){e.set(n,y(t))})):"set"===n?t.forEach((function(t){e.add(y(t))})):Reflect.ownKeys(t).forEach((function(n){var r=t[n];e[n]=y(r)})),e},m=function(t,n){switch(void 0===n&&(n={}),t){case"array":return[];case"function":return n;case"set":return new Set;case"map":return new Map;case"date":return new Date(n);case"regExp":return new RegExp(n);case"math":return Math;default:return{}}},g=function(t){function n(){}return n.prototype=t,new n},b=function(t,n){return void 0===n&&(n=function(){}),n.prototype=g(t.prototype),n.prototype.super=t,n.prototype.constructor=n,n},w=function(t,n){void 0===n&&(n=!1);for(var r=[],o=2;o<arguments.length;o++)r[o-2]=arguments[o];return t._instance&&!n||(t._instance=new(t.bind.apply(t,e([void 0],r,!1)))),t._instance},j=function(t){return function(n){for(var e in t)Reflect.has(n.prototype,e)||(n.prototype[e]=t[e])}},E=function(t){if("string"!==c(t))return null;try{return JSON.parse(t)}catch(t){return null}},S=function(t){if(!u(t,["array","object","set","map"]))return"";try{return JSON.stringify(t)}catch(t){return""}},O=function(t){return t&&t===t.window},M=function(t){void 0===t&&(t={});var n=Object.create(null);return Reflect.ownKeys(t).forEach((function(e){return n[e]=t[e]})),n},A=function(t){void 0===t&&(t={});var n=M(t);return Reflect.ownKeys(n).length<=0},L={getValue:s,setValue:p,mixIn:v,enumInversion:d,isNotObject:h,cloneDeep:y,createObjectVariable:m,createObject:g,inherit:b,getInstance:w,classDecorator:j,stringToJson:E,jsonToString:S,isWindow:O,emptyObject:M,isEmptyObject:A},T=function(t){return t.sort((function(){return Math.random()-.5}))},k=function(t){return Array.from(new Set(t))},x=function(t,n){return void 0===n&&(n=[]),t.forEach((function(t){return"array"===c(t)?x(t,n):n.push(t)})),n},D=function(t,n){return void 0===n&&(n=0),{item:t[n],current:(n+1)%t.length}},I={arrayRandom:T,arrayUniq:k,arrayDemote:x,arrayLoop:D},N=void 0,R=function(t,n){var r=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];r||(r=setTimeout((function(){t.call.apply(t,e([N],o,!1)),r=null}),n))}},B=function(t,n){var r=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];r&&(clearTimeout(r),r=null),r=setTimeout((function(){t.call.apply(t,e([N],o,!1))}),n)}},J=function(t){var n,e;return void 0===t&&(t=0),{promise:new Promise((function(r,o){n=r,e=o,t>0&&setTimeout((function(){return e("timeout")}),t)})),resolve:n,reject:e}},F=function(t){return t.then((function(t){return[null,t]})).catch((function(t){return[t]}))},q=function(t,n){if(void 0===n&&(n=0),!t)throw Error("callback is empty");var e="undefined"!=typeof process?setImmediate:requestAnimationFrame,r=performance,o=r.now(),i=!1,a=function(){i||(r.now()-o>=n&&(o=r.now(),t(o)),e(a))};return a(),function(){return i=!0}},K={throttle:R,debounce:B,defer:J,catchAwait:F},P=function(t){var n,e,r=t.ele,o=t.style,i=t.attr,a=t.parent,c=r instanceof HTMLElement?r:document.createElement(null!=r?r:"div");return o&&(null===(n=Object.keys(o))||void 0===n||n.forEach((function(t){return c.style[t]=o[t]}))),i&&(null===(e=Object.keys(i))||void 0===e||e.forEach((function(t){return c[t]=i[t]}))),a&&a.appendChild(c),c},V={createElement:P},z=function(t,n,e){t.addEventListener?t.addEventListener(n,e,!1):t["on"+n]=e},C=function(t){(t=t||window.event).stopPropagation?t.stopPropagation():t.cancelBubble=!1},H=function(t){(t=t||window.event).preventDefault?t.preventDefault():t.returnValue=!1},W=function(t,n,e){if(t.removeEventListener)t.removeEventListener(n,e,!1);else{var r="on"+n;"function"==typeof t[r]&&(t[r]=function(){})}},_=function(t,n){var e=new Event(n);t.dispatchEvent(e)},U={addHandler:z,stopBubble:C,stopDefault:H,removeHandler:W,dispatchEvent:_},Z=function(t,n){try{localStorage.setItem(t,JSON.stringify(n))}catch(t){console.error(t)}},G=function(t){try{var n=localStorage.getItem(t);return null==n?null:JSON.parse(n)}catch(t){return console.error(t),null}},Q=function(t){try{t&&localStorage.removeItem(t),!t&&localStorage.clear()}catch(t){console.error(t)}},X={setStorage:Z,getStorage:G,clearStorage:Q},Y=function(t,n,e){void 0===n&&(n=!1),void 0===e&&(e=!0),n&&(process.stdout.clearLine(0),process.stdout.cursorTo(0)),process.stdout.write(t),e&&process.stdout.write("\n")},$=function(t){return Y(t,!0,!1)},tt=["\\","|","/","—","—"],nt=function(t){var n;void 0===t&&(t={});var e=t.loopList,r=void 0===e?tt:e,o=t.isStop,i=void 0!==o&&o,a=t.timer,c=void 0===a?100:a,u=t.index,f=void 0===u?0:u,l=null!==(n=null==r?void 0:r.length)&&void 0!==n?n:0;if(!l)return t;if(i)return $("\n");f>=l-1&&(f=0);var s=r[f++];return $(s),setTimeout((function(){t.index=f,nt(t)}),c),t},et={logOneLine:Y,logLoop:nt},rt=function(){function t(t){this.fn=t,this.id=null,this.duration=1/0,this.isActive=!1}return t.prototype.start=function(t){if(!this.isActive)return this.duration=null!=t?t:1/0,this.isActive=!0,this.animate()},t.prototype.stop=function(t){void 0===t&&(t=this.id),this.isActive=!1,cancelAnimationFrame(t)},t.prototype.animate=function(t){if(void 0===t&&(t=0),this.isActive&&this.duration-- >0)return this.fn(t),this.id=requestAnimationFrame(this.animate.bind(this)),this.id},t}();function ot(t,n,e){var r=1-e,o=e*e;return[2*r*e*t+o,2*r*e*n+o]}function it(t,n,e,r,o){var i=3*t,a=3*n,c=3*(e-t)-i,u=3*(r-n)-a,f=1-a-u;return[(1-i-c)*Math.pow(o,3)+c*Math.pow(o,2)+i*o,f*Math.pow(o,3)+u*Math.pow(o,2)+a*o]}function at(t){return 0===t||1===t?1:t*at(t-1)}function ct(t,n){return at(t)/(at(n)*at(t-n))}function ut(t,n){for(var e=t.length-1,r=[0,0],o=0;o<=e;o++){var i=ct(e,o)*Math.pow(1-n,e-o)*Math.pow(n,o);r[0]+=i*t[o][0],r[1]+=i*t[o][1]}return r}var ft={AnimateFrame:rt,quadraticBezier:ot,cubicBezier:it,factorial:at,combination:ct,NBezier:ut},lt=n(n(n(n(n(n(n(n(n(n({},L),l),I),K),V),r),U),X),et),ft);export{rt as AnimateFrame,ut as NBezier,z as addHandler,x as arrayDemote,D as arrayLoop,T as arrayRandom,k as arrayUniq,F as catchAwait,j as classDecorator,Q as clearStorage,y as cloneDeep,ct as combination,P as createElement,g as createObject,m as createObjectVariable,it as cubicBezier,B as debounce,lt as default,J as defer,_ as dispatchEvent,M as emptyObject,d as enumInversion,at as factorial,w as getInstance,G as getStorage,c as getType,u as getTypeByList,s as getValue,b as inherit,A as isEmptyObject,h as isNotObject,O as isWindow,S as jsonToString,nt as logLoop,Y as logOneLine,v as mixIn,ot as quadraticBezier,o as randomNum,W as removeHandler,q as requestFrame,Z as setStorage,p as setValue,C as stopBubble,H as stopDefault,E as stringToJson,R as throttle,f as toKebabCase,t as types,a as urlJoin,i as urlSplit};
1
+ var t,n=function(){return n=Object.assign||function(t){for(var n,e=1,r=arguments.length;e<r;e++)for(var o in n=arguments[e])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},n.apply(this,arguments)};function e(t,n,e){if(e||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return t.concat(r||Array.prototype.slice.call(n))}!function(t){t["[object Array]"]="array",t["[object Object]"]="object",t["[object Function]"]="function",t["[object Set]"]="set",t["[object Map]"]="map",t["[object WeakMap]"]="weakMap",t["[object WeakSet]"]="weakSet",t["[object Date]"]="date",t["[object RegExp]"]="regExp",t["[object Math]"]="math"}(t||(t={}));var r={types:t},o=function(t,n,e){return void 0===e&&(e=!1),Math.floor(Math.random()*(n-t+(e?1:0))+t)},i=function(t){var n={};return t.includes("?")?(t.split("?")[1].split("&").forEach((function(t){var e=t.split("=")[0];n[e]=t.split("=")[1]})),n):n},a=function(t,n){void 0===n&&(n={});var e=Object.keys(n);if(0===e.length)return t;var r=e.map((function(t){return"".concat(t,"=").concat(n[t])}));return"".concat(t).concat(t.includes("?")?"&":"?").concat(r.join("&"))},c=function(n){var e=typeof n;if(null===n)return"null";if("object"===e){var r=Object.prototype.toString.call(n);return t[r]}return e},u=function(t,n){void 0===n&&(n=[]);var e=c(t);return n.includes(e)},f=function(t,n){return void 0===n&&(n="-"),t.replace(/[A-Z]/g,(function(t){return"".concat(n).concat(t.toLowerCase())}))},l={randomNum:o,urlSplit:i,urlJoin:a,getType:c,getTypeByList:u,toKebabCase:f},s=function(t,n,e){void 0===e&&(e="");for(var r=0,o=n.split(".");r<o.length;r++){if(void 0===(t=t[o[r]]))return e}return t},p=function(t,n,e){void 0===e&&(e={});for(var r=n.split("."),o=r[r.length-1],i=t,a=0,c=r;a<c.length;a++){var u=c[a];if("object"!=typeof i&&void 0!==i)return t;!i&&(i={}),!i[u]&&(i[u]={}),o===u&&(i[o]=e),i=i[u]}return t},v=function(t,n,e){var r;for(var o in void 0===n&&(n={}),void 0===e&&(e=!1),n)for(var i in n[o]){var a=null!==(r=null==t?void 0:t.prototype)&&void 0!==r?r:t;(void 0===(null==t?void 0:t[i])||e)&&(a[i]=n[o][i])}return t},d=function(t){for(var n in t){var e=t[n];"string"!=typeof e||t[e]||(t[e]=n)}return t},h=function(t,n){return"object"!=typeof t||"null"===n},y=function(t){var n=c(t);if(h(t,n))return t;var e=m(n,t);return"map"===n?t.forEach((function(t,n){e.set(n,y(t))})):"set"===n?t.forEach((function(t){e.add(y(t))})):Reflect.ownKeys(t).forEach((function(n){var r=t[n];e[n]=y(r)})),e},m=function(t,n){switch(void 0===n&&(n={}),t){case"array":return[];case"function":return n;case"set":return new Set;case"map":return new Map;case"date":return new Date(n);case"regExp":return new RegExp(n);case"math":return Math;default:return{}}},g=function(t){function n(){}return n.prototype=t,new n},b=function(t,n){return void 0===n&&(n=function(){}),n.prototype=g(t.prototype),n.prototype.super=t,n.prototype.constructor=n,n},w=function(t,n){void 0===n&&(n=!1);for(var r=[],o=2;o<arguments.length;o++)r[o-2]=arguments[o];return t._instance&&!n||(t._instance=new(t.bind.apply(t,e([void 0],r,!1)))),t._instance},j=function(t){return function(n){for(var e in t)Reflect.has(n.prototype,e)||(n.prototype[e]=t[e])}},E=function(t){if("string"!==c(t))return null;try{return JSON.parse(t)}catch(t){return null}},S=function(t){if(!u(t,["array","object","set","map"]))return"";try{return JSON.stringify(t)}catch(t){return""}},O=function(t){return t&&t===t.window},M=function(t){void 0===t&&(t={});var n=Object.create(null);return Reflect.ownKeys(t).forEach((function(e){return n[e]=t[e]})),n},A=function(t){void 0===t&&(t={});var n=M(t);return Reflect.ownKeys(n).length<=0},L={getValue:s,setValue:p,mixIn:v,enumInversion:d,isNotObject:h,cloneDeep:y,createObjectVariable:m,createObject:g,inherit:b,getInstance:w,classDecorator:j,stringToJson:E,jsonToString:S,isWindow:O,emptyObject:M,isEmptyObject:A},T=function(t){return t.sort((function(){return Math.random()-.5}))},k=function(t){return Array.from(new Set(t))},x=function(t,n){return void 0===n&&(n=[]),t.forEach((function(t){return"array"===c(t)?x(t,n):n.push(t)})),n},D=function(t,n){return void 0===n&&(n=0),{item:t[n],current:(n+1)%t.length}},I={arrayRandom:T,arrayUniq:k,arrayDemote:x,arrayLoop:D},N=void 0,R=function(t,n){var r=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];r||(r=setTimeout((function(){t.call.apply(t,e([N],o,!1)),r=null}),n))}},B=function(t,n){var r=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];r&&(clearTimeout(r),r=null),r=setTimeout((function(){t.call.apply(t,e([N],o,!1))}),n)}},J=function(t){var n,e;return void 0===t&&(t=0),{promise:new Promise((function(r,o){n=r,e=o,t>0&&setTimeout((function(){return e("timeout")}),t)})),resolve:n,reject:e}},F=function(t){return t?t.then((function(t){return[null,t]})).catch((function(t){return[t]})):[new Error("defer is empty")]},q=function(t,n){if(void 0===n&&(n=0),!t)throw Error("callback is empty");var e="undefined"!=typeof process?setImmediate:requestAnimationFrame,r=performance,o=r.now(),i=!1,a=function(){i||(r.now()-o>=n&&(o=r.now(),t(o)),e(a))};return a(),function(){return i=!0}},K={throttle:R,debounce:B,defer:J,catchAwait:F},P=function(t){var n,e,r=t.ele,o=t.style,i=t.attr,a=t.parent,c=r instanceof HTMLElement?r:document.createElement(null!=r?r:"div");return o&&(null===(n=Object.keys(o))||void 0===n||n.forEach((function(t){return c.style[t]=o[t]}))),i&&(null===(e=Object.keys(i))||void 0===e||e.forEach((function(t){return c[t]=i[t]}))),a&&a.appendChild(c),c},V={createElement:P},z=function(t,n,e){t.addEventListener?t.addEventListener(n,e,!1):t["on"+n]=e},C=function(t){(t=t||window.event).stopPropagation?t.stopPropagation():t.cancelBubble=!1},H=function(t){(t=t||window.event).preventDefault?t.preventDefault():t.returnValue=!1},W=function(t,n,e){if(t.removeEventListener)t.removeEventListener(n,e,!1);else{var r="on"+n;"function"==typeof t[r]&&(t[r]=function(){})}},_=function(t,n){var e=new Event(n);t.dispatchEvent(e)},U={addHandler:z,stopBubble:C,stopDefault:H,removeHandler:W,dispatchEvent:_},Z=function(t,n){try{localStorage.setItem(t,JSON.stringify(n))}catch(t){console.error(t)}},G=function(t){try{var n=localStorage.getItem(t);return null==n?null:JSON.parse(n)}catch(t){return console.error(t),null}},Q=function(t){try{t&&localStorage.removeItem(t),!t&&localStorage.clear()}catch(t){console.error(t)}},X={setStorage:Z,getStorage:G,clearStorage:Q},Y=function(t,n,e){void 0===n&&(n=!1),void 0===e&&(e=!0),n&&(process.stdout.clearLine(0),process.stdout.cursorTo(0)),process.stdout.write(t),e&&process.stdout.write("\n")},$=function(t){return Y(t,!0,!1)},tt=["\\","|","/","—","—"],nt=function(t){var n;void 0===t&&(t={});var e=t.loopList,r=void 0===e?tt:e,o=t.isStop,i=void 0!==o&&o,a=t.timer,c=void 0===a?100:a,u=t.index,f=void 0===u?0:u,l=null!==(n=null==r?void 0:r.length)&&void 0!==n?n:0;if(!l)return t;if(i)return $("\n");f>=l-1&&(f=0);var s=r[f++];return $(s),setTimeout((function(){t.index=f,nt(t)}),c),t},et={logOneLine:Y,logLoop:nt},rt=function(){function t(t){this.fn=t,this.id=null,this.duration=1/0,this.isActive=!1}return t.prototype.start=function(t){if(!this.isActive)return this.duration=null!=t?t:1/0,this.isActive=!0,this.animate()},t.prototype.stop=function(t){void 0===t&&(t=this.id),this.isActive=!1,cancelAnimationFrame(t)},t.prototype.animate=function(t){if(void 0===t&&(t=0),this.isActive&&this.duration-- >0)return this.fn(t),this.id=requestAnimationFrame(this.animate.bind(this)),this.id},t}();function ot(t,n,e){var r=1-e,o=e*e;return[2*r*e*t+o,2*r*e*n+o]}function it(t,n,e,r,o){var i=3*t,a=3*n,c=3*(e-t)-i,u=3*(r-n)-a,f=1-a-u;return[(1-i-c)*Math.pow(o,3)+c*Math.pow(o,2)+i*o,f*Math.pow(o,3)+u*Math.pow(o,2)+a*o]}function at(t){return 0===t||1===t?1:t*at(t-1)}function ct(t,n){return at(t)/(at(n)*at(t-n))}function ut(t,n){for(var e=t.length-1,r=[0,0],o=0;o<=e;o++){var i=ct(e,o)*Math.pow(1-n,e-o)*Math.pow(n,o);r[0]+=i*t[o][0],r[1]+=i*t[o][1]}return r}var ft={AnimateFrame:rt,quadraticBezier:ot,cubicBezier:it,factorial:at,combination:ct,NBezier:ut},lt=n(n(n(n(n(n(n(n(n(n({},L),l),I),K),V),r),U),X),et),ft);export{rt as AnimateFrame,ut as NBezier,z as addHandler,x as arrayDemote,D as arrayLoop,T as arrayRandom,k as arrayUniq,F as catchAwait,j as classDecorator,Q as clearStorage,y as cloneDeep,ct as combination,P as createElement,g as createObject,m as createObjectVariable,it as cubicBezier,B as debounce,lt as default,J as defer,_ as dispatchEvent,M as emptyObject,d as enumInversion,at as factorial,w as getInstance,G as getStorage,c as getType,u as getTypeByList,s as getValue,b as inherit,A as isEmptyObject,h as isNotObject,O as isWindow,S as jsonToString,nt as logLoop,Y as logOneLine,v as mixIn,ot as quadraticBezier,o as randomNum,W as removeHandler,q as requestFrame,Z as setStorage,p as setValue,C as stopBubble,H as stopDefault,E as stringToJson,R as throttle,f as toKebabCase,t as types,a as urlJoin,i as urlSplit};
@@ -1,9 +1,9 @@
1
1
  export type IKey = string | symbol | number;
2
2
  export type IObject<V = any, K extends string | number | symbol = IKey> = Record<K, V>;
3
- export interface IPromise extends IObject<any> {
4
- promise?: Promise<void>;
5
- resolve?: (res?: any) => unknown;
6
- reject?: (err?: any) => unknown;
3
+ export interface IPromise<T = any> {
4
+ promise: Promise<T>;
5
+ resolve: (res?: T) => unknown;
6
+ reject: (err?: any) => unknown;
7
7
  }
8
8
  export type IInstance<T> = {
9
9
  _instance: Function;
@@ -28,8 +28,8 @@ export type IStringToJson = (target: string) => IObject<any> | null;
28
28
  export type IJsonToString = (target: IObject<any>) => string;
29
29
  export type IThrottle = (fn: Function, time: number) => (...args: any[]) => void;
30
30
  export type IDebounce = (fn: Function, time: number) => (...args: any[]) => void;
31
- export type IDefer = (timer?: number) => IPromise;
32
- export type ICatchAwait<T extends Promise<any>> = (defer: T) => T;
31
+ export type IDefer = <T>(timer?: number) => IPromise<T>;
32
+ export type ICatchAwait<T extends Promise<any>> = (defer?: T) => T | [Error];
33
33
  export type IRequestFrame = (callback: (start: number) => void, delay: number) => () => void;
34
34
  export type IArrayRandom<T extends any[]> = (arr: T) => T;
35
35
  export type IArrayUniq<T extends any[]> = (arr: T) => T;
@@ -1,4 +1,4 @@
1
- import { ICatchAwait, IThrottle, IDebounce, IDefer, IRequestFrame } from "./types";
1
+ import { ICatchAwait, IDebounce, IDefer, IRequestFrame, IThrottle } from "./types";
2
2
  export declare const throttle: IThrottle;
3
3
  export declare const debounce: IDebounce;
4
4
  export declare const defer: IDefer;
package/dist/umd/index.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).UtilsLib={})}(this,(function(t){"use strict";var e,n=function(){return n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function r(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}t.types=void 0,(e=t.types||(t.types={}))["[object Array]"]="array",e["[object Object]"]="object",e["[object Function]"]="function",e["[object Set]"]="set",e["[object Map]"]="map",e["[object WeakMap]"]="weakMap",e["[object WeakSet]"]="weakSet",e["[object Date]"]="date",e["[object RegExp]"]="regExp",e["[object Math]"]="math";var o={types:t.types},i=function(t,e,n){return void 0===n&&(n=!1),Math.floor(Math.random()*(e-t+(n?1:0))+t)},a=function(t){var e={};return t.includes("?")?(t.split("?")[1].split("&").forEach((function(t){var n=t.split("=")[0];e[n]=t.split("=")[1]})),e):e},c=function(t,e){void 0===e&&(e={});var n=Object.keys(e);if(0===n.length)return t;var r=n.map((function(t){return"".concat(t,"=").concat(e[t])}));return"".concat(t).concat(t.includes("?")?"&":"?").concat(r.join("&"))},u=function(e){var n=typeof e;if(null===e)return"null";if("object"===n){var r=Object.prototype.toString.call(e);return t.types[r]}return n},l=function(t,e){void 0===e&&(e=[]);var n=u(t);return e.includes(n)},s=function(t,e){return void 0===e&&(e="-"),t.replace(/[A-Z]/g,(function(t){return"".concat(e).concat(t.toLowerCase())}))},f={randomNum:i,urlSplit:a,urlJoin:c,getType:u,getTypeByList:l,toKebabCase:s},p=function(t,e,n){void 0===n&&(n="");for(var r=0,o=e.split(".");r<o.length;r++){if(void 0===(t=t[o[r]]))return n}return t},d=function(t,e,n){void 0===n&&(n={});for(var r=e.split("."),o=r[r.length-1],i=t,a=0,c=r;a<c.length;a++){var u=c[a];if("object"!=typeof i&&void 0!==i)return t;!i&&(i={}),!i[u]&&(i[u]={}),o===u&&(i[o]=n),i=i[u]}return t},v=function(t,e,n){var r;for(var o in void 0===e&&(e={}),void 0===n&&(n=!1),e)for(var i in e[o]){var a=null!==(r=null==t?void 0:t.prototype)&&void 0!==r?r:t;(void 0===(null==t?void 0:t[i])||n)&&(a[i]=e[o][i])}return t},y=function(t){for(var e in t){var n=t[e];"string"!=typeof n||t[n]||(t[n]=e)}return t},h=function(t,e){return"object"!=typeof t||"null"===e},m=function(t){var e=u(t);if(h(t,e))return t;var n=b(e,t);return"map"===e?t.forEach((function(t,e){n.set(e,m(t))})):"set"===e?t.forEach((function(t){n.add(m(t))})):Reflect.ownKeys(t).forEach((function(e){var r=t[e];n[e]=m(r)})),n},b=function(t,e){switch(void 0===e&&(e={}),t){case"array":return[];case"function":return e;case"set":return new Set;case"map":return new Map;case"date":return new Date(e);case"regExp":return new RegExp(e);case"math":return Math;default:return{}}},g=function(t){function e(){}return e.prototype=t,new e},j=function(t,e){return void 0===e&&(e=function(){}),e.prototype=g(t.prototype),e.prototype.super=t,e.prototype.constructor=e,e},w=function(t,e){void 0===e&&(e=!1);for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];return t._instance&&!e||(t._instance=new(t.bind.apply(t,r([void 0],n,!1)))),t._instance},E=function(t){return function(e){for(var n in t)Reflect.has(e.prototype,n)||(e.prototype[n]=t[n])}},O=function(t){if("string"!==u(t))return null;try{return JSON.parse(t)}catch(t){return null}},S=function(t){if(!l(t,["array","object","set","map"]))return"";try{return JSON.stringify(t)}catch(t){return""}},A=function(t){return t&&t===t.window},L=function(t){void 0===t&&(t={});var e=Object.create(null);return Reflect.ownKeys(t).forEach((function(n){return e[n]=t[n]})),e},M=function(t){void 0===t&&(t={});var e=L(t);return Reflect.ownKeys(e).length<=0},T={getValue:p,setValue:d,mixIn:v,enumInversion:y,isNotObject:h,cloneDeep:m,createObjectVariable:b,createObject:g,inherit:j,getInstance:w,classDecorator:E,stringToJson:O,jsonToString:S,isWindow:A,emptyObject:L,isEmptyObject:M},D=function(t){return t.sort((function(){return Math.random()-.5}))},x=function(t){return Array.from(new Set(t))},B=function(t,e){return void 0===e&&(e=[]),t.forEach((function(t){return"array"===u(t)?B(t,e):e.push(t)})),e},I=function(t,e){return void 0===e&&(e=0),{item:t[e],current:(e+1)%t.length}},N={arrayRandom:D,arrayUniq:x,arrayDemote:B,arrayLoop:I},k=void 0,J=function(t,e){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n||(n=setTimeout((function(){t.call.apply(t,r([k],o,!1)),n=null}),e))}},R=function(t,e){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n&&(clearTimeout(n),n=null),n=setTimeout((function(){t.call.apply(t,r([k],o,!1))}),e)}},q=function(t){var e,n;return void 0===t&&(t=0),{promise:new Promise((function(r,o){e=r,n=o,t>0&&setTimeout((function(){return n("timeout")}),t)})),resolve:e,reject:n}},F=function(t){return t.then((function(t){return[null,t]})).catch((function(t){return[t]}))},V={throttle:J,debounce:R,defer:q,catchAwait:F},z=function(t){var e,n,r=t.ele,o=t.style,i=t.attr,a=t.parent,c=r instanceof HTMLElement?r:document.createElement(null!=r?r:"div");return o&&(null===(e=Object.keys(o))||void 0===e||e.forEach((function(t){return c.style[t]=o[t]}))),i&&(null===(n=Object.keys(i))||void 0===n||n.forEach((function(t){return c[t]=i[t]}))),a&&a.appendChild(c),c},H={createElement:z},K=function(t,e,n){t.addEventListener?t.addEventListener(e,n,!1):t["on"+e]=n},P=function(t){(t=t||window.event).stopPropagation?t.stopPropagation():t.cancelBubble=!1},_=function(t){(t=t||window.event).preventDefault?t.preventDefault():t.returnValue=!1},C=function(t,e,n){if(t.removeEventListener)t.removeEventListener(e,n,!1);else{var r="on"+e;"function"==typeof t[r]&&(t[r]=function(){})}},W=function(t,e){var n=new Event(e);t.dispatchEvent(n)},U={addHandler:K,stopBubble:P,stopDefault:_,removeHandler:C,dispatchEvent:W},Z=function(t,e){try{localStorage.setItem(t,JSON.stringify(e))}catch(t){console.error(t)}},G=function(t){try{var e=localStorage.getItem(t);return null==e?null:JSON.parse(e)}catch(t){return console.error(t),null}},Q=function(t){try{t&&localStorage.removeItem(t),!t&&localStorage.clear()}catch(t){console.error(t)}},X={setStorage:Z,getStorage:G,clearStorage:Q},Y=function(t,e,n){void 0===e&&(e=!1),void 0===n&&(n=!0),e&&(process.stdout.clearLine(0),process.stdout.cursorTo(0)),process.stdout.write(t),n&&process.stdout.write("\n")},$=function(t){return Y(t,!0,!1)},tt=["\\","|","/","—","—"],et=function(t){var e;void 0===t&&(t={});var n=t.loopList,r=void 0===n?tt:n,o=t.isStop,i=void 0!==o&&o,a=t.timer,c=void 0===a?100:a,u=t.index,l=void 0===u?0:u,s=null!==(e=null==r?void 0:r.length)&&void 0!==e?e:0;if(!s)return t;if(i)return $("\n");l>=s-1&&(l=0);var f=r[l++];return $(f),setTimeout((function(){t.index=l,et(t)}),c),t},nt={logOneLine:Y,logLoop:et},rt=function(){function t(t){this.fn=t,this.id=null,this.duration=1/0,this.isActive=!1}return t.prototype.start=function(t){if(!this.isActive)return this.duration=null!=t?t:1/0,this.isActive=!0,this.animate()},t.prototype.stop=function(t){void 0===t&&(t=this.id),this.isActive=!1,cancelAnimationFrame(t)},t.prototype.animate=function(t){if(void 0===t&&(t=0),this.isActive&&this.duration-- >0)return this.fn(t),this.id=requestAnimationFrame(this.animate.bind(this)),this.id},t}();function ot(t,e,n){var r=1-n,o=n*n;return[2*r*n*t+o,2*r*n*e+o]}function it(t,e,n,r,o){var i=3*t,a=3*e,c=3*(n-t)-i,u=3*(r-e)-a,l=1-a-u;return[(1-i-c)*Math.pow(o,3)+c*Math.pow(o,2)+i*o,l*Math.pow(o,3)+u*Math.pow(o,2)+a*o]}function at(t){return 0===t||1===t?1:t*at(t-1)}function ct(t,e){return at(t)/(at(e)*at(t-e))}function ut(t,e){for(var n=t.length-1,r=[0,0],o=0;o<=n;o++){var i=ct(n,o)*Math.pow(1-e,n-o)*Math.pow(e,o);r[0]+=i*t[o][0],r[1]+=i*t[o][1]}return r}var lt={AnimateFrame:rt,quadraticBezier:ot,cubicBezier:it,factorial:at,combination:ct,NBezier:ut},st=n(n(n(n(n(n(n(n(n(n({},T),f),N),V),H),o),U),X),nt),lt);t.AnimateFrame=rt,t.NBezier=ut,t.addHandler=K,t.arrayDemote=B,t.arrayLoop=I,t.arrayRandom=D,t.arrayUniq=x,t.catchAwait=F,t.classDecorator=E,t.clearStorage=Q,t.cloneDeep=m,t.combination=ct,t.createElement=z,t.createObject=g,t.createObjectVariable=b,t.cubicBezier=it,t.debounce=R,t.default=st,t.defer=q,t.dispatchEvent=W,t.emptyObject=L,t.enumInversion=y,t.factorial=at,t.getInstance=w,t.getStorage=G,t.getType=u,t.getTypeByList=l,t.getValue=p,t.inherit=j,t.isEmptyObject=M,t.isNotObject=h,t.isWindow=A,t.jsonToString=S,t.logLoop=et,t.logOneLine=Y,t.mixIn=v,t.quadraticBezier=ot,t.randomNum=i,t.removeHandler=C,t.requestFrame=function(t,e){if(void 0===e&&(e=0),!t)throw Error("callback is empty");var n="undefined"!=typeof process?setImmediate:requestAnimationFrame,r=performance,o=r.now(),i=!1,a=function(){i||(r.now()-o>=e&&(o=r.now(),t(o)),n(a))};return a(),function(){return i=!0}},t.setStorage=Z,t.setValue=d,t.stopBubble=P,t.stopDefault=_,t.stringToJson=O,t.throttle=J,t.toKebabCase=s,t.urlJoin=c,t.urlSplit=a,Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).UtilsLib={})}(this,(function(t){"use strict";var e,n=function(){return n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function r(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}t.types=void 0,(e=t.types||(t.types={}))["[object Array]"]="array",e["[object Object]"]="object",e["[object Function]"]="function",e["[object Set]"]="set",e["[object Map]"]="map",e["[object WeakMap]"]="weakMap",e["[object WeakSet]"]="weakSet",e["[object Date]"]="date",e["[object RegExp]"]="regExp",e["[object Math]"]="math";var o={types:t.types},i=function(t,e,n){return void 0===n&&(n=!1),Math.floor(Math.random()*(e-t+(n?1:0))+t)},a=function(t){var e={};return t.includes("?")?(t.split("?")[1].split("&").forEach((function(t){var n=t.split("=")[0];e[n]=t.split("=")[1]})),e):e},c=function(t,e){void 0===e&&(e={});var n=Object.keys(e);if(0===n.length)return t;var r=n.map((function(t){return"".concat(t,"=").concat(e[t])}));return"".concat(t).concat(t.includes("?")?"&":"?").concat(r.join("&"))},u=function(e){var n=typeof e;if(null===e)return"null";if("object"===n){var r=Object.prototype.toString.call(e);return t.types[r]}return n},l=function(t,e){void 0===e&&(e=[]);var n=u(t);return e.includes(n)},s=function(t,e){return void 0===e&&(e="-"),t.replace(/[A-Z]/g,(function(t){return"".concat(e).concat(t.toLowerCase())}))},f={randomNum:i,urlSplit:a,urlJoin:c,getType:u,getTypeByList:l,toKebabCase:s},p=function(t,e,n){void 0===n&&(n="");for(var r=0,o=e.split(".");r<o.length;r++){if(void 0===(t=t[o[r]]))return n}return t},d=function(t,e,n){void 0===n&&(n={});for(var r=e.split("."),o=r[r.length-1],i=t,a=0,c=r;a<c.length;a++){var u=c[a];if("object"!=typeof i&&void 0!==i)return t;!i&&(i={}),!i[u]&&(i[u]={}),o===u&&(i[o]=n),i=i[u]}return t},v=function(t,e,n){var r;for(var o in void 0===e&&(e={}),void 0===n&&(n=!1),e)for(var i in e[o]){var a=null!==(r=null==t?void 0:t.prototype)&&void 0!==r?r:t;(void 0===(null==t?void 0:t[i])||n)&&(a[i]=e[o][i])}return t},y=function(t){for(var e in t){var n=t[e];"string"!=typeof n||t[n]||(t[n]=e)}return t},h=function(t,e){return"object"!=typeof t||"null"===e},m=function(t){var e=u(t);if(h(t,e))return t;var n=b(e,t);return"map"===e?t.forEach((function(t,e){n.set(e,m(t))})):"set"===e?t.forEach((function(t){n.add(m(t))})):Reflect.ownKeys(t).forEach((function(e){var r=t[e];n[e]=m(r)})),n},b=function(t,e){switch(void 0===e&&(e={}),t){case"array":return[];case"function":return e;case"set":return new Set;case"map":return new Map;case"date":return new Date(e);case"regExp":return new RegExp(e);case"math":return Math;default:return{}}},g=function(t){function e(){}return e.prototype=t,new e},w=function(t,e){return void 0===e&&(e=function(){}),e.prototype=g(t.prototype),e.prototype.super=t,e.prototype.constructor=e,e},j=function(t,e){void 0===e&&(e=!1);for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];return t._instance&&!e||(t._instance=new(t.bind.apply(t,r([void 0],n,!1)))),t._instance},E=function(t){return function(e){for(var n in t)Reflect.has(e.prototype,n)||(e.prototype[n]=t[n])}},O=function(t){if("string"!==u(t))return null;try{return JSON.parse(t)}catch(t){return null}},S=function(t){if(!l(t,["array","object","set","map"]))return"";try{return JSON.stringify(t)}catch(t){return""}},A=function(t){return t&&t===t.window},L=function(t){void 0===t&&(t={});var e=Object.create(null);return Reflect.ownKeys(t).forEach((function(n){return e[n]=t[n]})),e},M=function(t){void 0===t&&(t={});var e=L(t);return Reflect.ownKeys(e).length<=0},T={getValue:p,setValue:d,mixIn:v,enumInversion:y,isNotObject:h,cloneDeep:m,createObjectVariable:b,createObject:g,inherit:w,getInstance:j,classDecorator:E,stringToJson:O,jsonToString:S,isWindow:A,emptyObject:L,isEmptyObject:M},D=function(t){return t.sort((function(){return Math.random()-.5}))},x=function(t){return Array.from(new Set(t))},B=function(t,e){return void 0===e&&(e=[]),t.forEach((function(t){return"array"===u(t)?B(t,e):e.push(t)})),e},I=function(t,e){return void 0===e&&(e=0),{item:t[e],current:(e+1)%t.length}},N={arrayRandom:D,arrayUniq:x,arrayDemote:B,arrayLoop:I},k=void 0,J=function(t,e){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n||(n=setTimeout((function(){t.call.apply(t,r([k],o,!1)),n=null}),e))}},R=function(t,e){var n=null;return function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n&&(clearTimeout(n),n=null),n=setTimeout((function(){t.call.apply(t,r([k],o,!1))}),e)}},q=function(t){var e,n;return void 0===t&&(t=0),{promise:new Promise((function(r,o){e=r,n=o,t>0&&setTimeout((function(){return n("timeout")}),t)})),resolve:e,reject:n}},F=function(t){return t?t.then((function(t){return[null,t]})).catch((function(t){return[t]})):[new Error("defer is empty")]},V={throttle:J,debounce:R,defer:q,catchAwait:F},z=function(t){var e,n,r=t.ele,o=t.style,i=t.attr,a=t.parent,c=r instanceof HTMLElement?r:document.createElement(null!=r?r:"div");return o&&(null===(e=Object.keys(o))||void 0===e||e.forEach((function(t){return c.style[t]=o[t]}))),i&&(null===(n=Object.keys(i))||void 0===n||n.forEach((function(t){return c[t]=i[t]}))),a&&a.appendChild(c),c},H={createElement:z},K=function(t,e,n){t.addEventListener?t.addEventListener(e,n,!1):t["on"+e]=n},P=function(t){(t=t||window.event).stopPropagation?t.stopPropagation():t.cancelBubble=!1},_=function(t){(t=t||window.event).preventDefault?t.preventDefault():t.returnValue=!1},C=function(t,e,n){if(t.removeEventListener)t.removeEventListener(e,n,!1);else{var r="on"+e;"function"==typeof t[r]&&(t[r]=function(){})}},W=function(t,e){var n=new Event(e);t.dispatchEvent(n)},U={addHandler:K,stopBubble:P,stopDefault:_,removeHandler:C,dispatchEvent:W},Z=function(t,e){try{localStorage.setItem(t,JSON.stringify(e))}catch(t){console.error(t)}},G=function(t){try{var e=localStorage.getItem(t);return null==e?null:JSON.parse(e)}catch(t){return console.error(t),null}},Q=function(t){try{t&&localStorage.removeItem(t),!t&&localStorage.clear()}catch(t){console.error(t)}},X={setStorage:Z,getStorage:G,clearStorage:Q},Y=function(t,e,n){void 0===e&&(e=!1),void 0===n&&(n=!0),e&&(process.stdout.clearLine(0),process.stdout.cursorTo(0)),process.stdout.write(t),n&&process.stdout.write("\n")},$=function(t){return Y(t,!0,!1)},tt=["\\","|","/","—","—"],et=function(t){var e;void 0===t&&(t={});var n=t.loopList,r=void 0===n?tt:n,o=t.isStop,i=void 0!==o&&o,a=t.timer,c=void 0===a?100:a,u=t.index,l=void 0===u?0:u,s=null!==(e=null==r?void 0:r.length)&&void 0!==e?e:0;if(!s)return t;if(i)return $("\n");l>=s-1&&(l=0);var f=r[l++];return $(f),setTimeout((function(){t.index=l,et(t)}),c),t},nt={logOneLine:Y,logLoop:et},rt=function(){function t(t){this.fn=t,this.id=null,this.duration=1/0,this.isActive=!1}return t.prototype.start=function(t){if(!this.isActive)return this.duration=null!=t?t:1/0,this.isActive=!0,this.animate()},t.prototype.stop=function(t){void 0===t&&(t=this.id),this.isActive=!1,cancelAnimationFrame(t)},t.prototype.animate=function(t){if(void 0===t&&(t=0),this.isActive&&this.duration-- >0)return this.fn(t),this.id=requestAnimationFrame(this.animate.bind(this)),this.id},t}();function ot(t,e,n){var r=1-n,o=n*n;return[2*r*n*t+o,2*r*n*e+o]}function it(t,e,n,r,o){var i=3*t,a=3*e,c=3*(n-t)-i,u=3*(r-e)-a,l=1-a-u;return[(1-i-c)*Math.pow(o,3)+c*Math.pow(o,2)+i*o,l*Math.pow(o,3)+u*Math.pow(o,2)+a*o]}function at(t){return 0===t||1===t?1:t*at(t-1)}function ct(t,e){return at(t)/(at(e)*at(t-e))}function ut(t,e){for(var n=t.length-1,r=[0,0],o=0;o<=n;o++){var i=ct(n,o)*Math.pow(1-e,n-o)*Math.pow(e,o);r[0]+=i*t[o][0],r[1]+=i*t[o][1]}return r}var lt={AnimateFrame:rt,quadraticBezier:ot,cubicBezier:it,factorial:at,combination:ct,NBezier:ut},st=n(n(n(n(n(n(n(n(n(n({},T),f),N),V),H),o),U),X),nt),lt);t.AnimateFrame=rt,t.NBezier=ut,t.addHandler=K,t.arrayDemote=B,t.arrayLoop=I,t.arrayRandom=D,t.arrayUniq=x,t.catchAwait=F,t.classDecorator=E,t.clearStorage=Q,t.cloneDeep=m,t.combination=ct,t.createElement=z,t.createObject=g,t.createObjectVariable=b,t.cubicBezier=it,t.debounce=R,t.default=st,t.defer=q,t.dispatchEvent=W,t.emptyObject=L,t.enumInversion=y,t.factorial=at,t.getInstance=j,t.getStorage=G,t.getType=u,t.getTypeByList=l,t.getValue=p,t.inherit=w,t.isEmptyObject=M,t.isNotObject=h,t.isWindow=A,t.jsonToString=S,t.logLoop=et,t.logOneLine=Y,t.mixIn=v,t.quadraticBezier=ot,t.randomNum=i,t.removeHandler=C,t.requestFrame=function(t,e){if(void 0===e&&(e=0),!t)throw Error("callback is empty");var n="undefined"!=typeof process?setImmediate:requestAnimationFrame,r=performance,o=r.now(),i=!1,a=function(){i||(r.now()-o>=e&&(o=r.now(),t(o)),n(a))};return a(),function(){return i=!0}},t.setStorage=Z,t.setValue=d,t.stopBubble=P,t.stopDefault=_,t.stringToJson=O,t.throttle=J,t.toKebabCase=s,t.urlJoin=c,t.urlSplit=a,Object.defineProperty(t,"__esModule",{value:!0})}));
@@ -1,9 +1,9 @@
1
1
  export type IKey = string | symbol | number;
2
2
  export type IObject<V = any, K extends string | number | symbol = IKey> = Record<K, V>;
3
- export interface IPromise extends IObject<any> {
4
- promise?: Promise<void>;
5
- resolve?: (res?: any) => unknown;
6
- reject?: (err?: any) => unknown;
3
+ export interface IPromise<T = any> {
4
+ promise: Promise<T>;
5
+ resolve: (res?: T) => unknown;
6
+ reject: (err?: any) => unknown;
7
7
  }
8
8
  export type IInstance<T> = {
9
9
  _instance: Function;
@@ -28,8 +28,8 @@ export type IStringToJson = (target: string) => IObject<any> | null;
28
28
  export type IJsonToString = (target: IObject<any>) => string;
29
29
  export type IThrottle = (fn: Function, time: number) => (...args: any[]) => void;
30
30
  export type IDebounce = (fn: Function, time: number) => (...args: any[]) => void;
31
- export type IDefer = (timer?: number) => IPromise;
32
- export type ICatchAwait<T extends Promise<any>> = (defer: T) => T;
31
+ export type IDefer = <T>(timer?: number) => IPromise<T>;
32
+ export type ICatchAwait<T extends Promise<any>> = (defer?: T) => T | [Error];
33
33
  export type IRequestFrame = (callback: (start: number) => void, delay: number) => () => void;
34
34
  export type IArrayRandom<T extends any[]> = (arr: T) => T;
35
35
  export type IArrayUniq<T extends any[]> = (arr: T) => T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utils-lib-js-lite",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "JavaScript工具函数,封装的一些常用的js函数,轻量化工具包",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/cjs/index.d.ts",