utils-lib-js-lite 1.0.0 → 1.1.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.
package/README.en.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Introduction
4
4
 
5
- JavaScript utility functions, packaging some commonly used js functions
5
+ JavaScript utility functions, packaging some commonly used js functions, lightweight toolkit
6
6
 
7
7
  ## Debugging instructions
8
8
 
@@ -354,9 +354,9 @@ Determines if the object is empty
354
354
  - `object` : the target object.
355
355
 
356
356
  ```javascript
357
- const o = isEmptyObject({name: "a u"});
357
+ const o = isEmptyObject({ name: "a u" });
358
358
  const o2 = isEmptyObject({});
359
- console.log(o, o2); // Output: false true
359
+ console.log(o, o2); // Output: false true
360
360
  ```
361
361
 
362
362
  #### array module
@@ -372,7 +372,7 @@ const originalArray = [1, 2, 3, 4, 5];
372
372
  const randomizedArray = arrayRandom(originalArray);
373
373
  console.log(randomizedArray);
374
374
  // Output: a randomly sorted array
375
- ````
375
+ ```
376
376
 
377
377
  ##### 2. `arrayUniq(arr: any[]): any[]`
378
378
 
@@ -401,6 +401,33 @@ console.log(demotedArray);
401
401
  // Output: reduced array [1, 2, 3, 4, 5]
402
402
  ```
403
403
 
404
+ ##### 4. arrayLoop(list: any[], current? : number): { item: any; current: number }
405
+
406
+ Walks through the elements in the group and returns the current element and its index.
407
+
408
+ - 'list' : The array to traverse.
409
+ - 'current' : indicates the index of the current element. The default is 0.
410
+
411
+ ```javascript
412
+ // Each time the arrayLoop function is called, current is incremented by 1 and takes the module length to loop to the beginning of the array.
413
+ const list = [
414
+ " Element 1",
415
+ "element 2",
416
+ " element 3",
417
+ "element 4",
418
+ " element 5",
419
+ ];
420
+ // Simulation loop multiple times
421
+ let c = 0;
422
+ Array(10)
423
+ .fill("")
424
+ .forEach(() => {
425
+ const { item, current } = arrayLoop(list, c);
426
+ c = current;
427
+ console.log(item, c); // 1,2,3,4,0,1,2,3,4,0
428
+ });
429
+ ```
430
+
404
431
  #### function module
405
432
 
406
433
  ##### 1. `throttle(fn: Function, time: number): Function`
@@ -758,3 +785,7 @@ https://gitee.com/DieHunter/task-queue
758
785
  #### js-request-lib
759
786
 
760
787
  https://gitee.com/DieHunter/js-request-lib
788
+
789
+ #### js-log-lib
790
+
791
+ https://gitee.com/DieHunter/js-log-lib
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## 介绍
4
4
 
5
- JavaScript 工具函数,封装的一些常用的 js 函数
5
+ JavaScript 工具函数,封装的一些常用的 js 函数,轻量化工具包
6
6
 
7
7
  ## 调试说明
8
8
 
@@ -401,6 +401,27 @@ console.log(demotedArray);
401
401
  // 输出: 降维后的数组 [1, 2, 3, 4, 5]
402
402
  ```
403
403
 
404
+ ##### 4. arrayLoop(list: any[], current?: number): { item: any; current: number }
405
+
406
+ 遍历数组中的元素,并返回当前元素及其索引。
407
+
408
+ - `list`: 要遍历的数组。
409
+ - `current`: 当前元素的索引,默认为 0。
410
+
411
+ ```javascript
412
+ // 每次调用arrayLoop函数时,current将加 1,并取模数组长度,以循环到数组的开始。
413
+ const list = ["元素1", "元素2", "元素3", "元素4", "元素5"];
414
+ // 模拟循环多次
415
+ let c = 0;
416
+ Array(10)
417
+ .fill("")
418
+ .forEach(() => {
419
+ const { item, current } = arrayLoop(list, c);
420
+ c = current;
421
+ console.log(item, c); // 1,2,3,4,0,1,2,3,4,0
422
+ });
423
+ ```
424
+
404
425
  #### function 模块
405
426
 
406
427
  ##### 1. `throttle(fn: Function, time: number): Function`
@@ -1,10 +1,12 @@
1
- import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./types";
1
+ import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray, IArrayLoop } from "./types";
2
2
  export declare const arrayRandom: IArrayRandom<any[]>;
3
3
  export declare const arrayUniq: IArrayUniq<any[]>;
4
4
  export declare const arrayDemote: IArrayDemote<IDemoteArray<any>>;
5
+ export declare const arrayLoop: IArrayLoop;
5
6
  declare const _default: {
6
7
  arrayRandom: IArrayRandom<any[]>;
7
8
  arrayUniq: IArrayUniq<any[]>;
8
9
  arrayDemote: IArrayDemote<IDemoteArray<any>>;
10
+ arrayLoop: IArrayLoop;
9
11
  };
10
12
  export default _default;
@@ -35,6 +35,7 @@ declare const _default: {
35
35
  arrayRandom: import("./types").IArrayRandom<any[]>;
36
36
  arrayUniq: import("./types").IArrayUniq<any[]>;
37
37
  arrayDemote: import("./types").IArrayDemote<import("./types").IDemoteArray<any>>;
38
+ arrayLoop: import("./types").IArrayLoop;
38
39
  randomNum: import("./types").IRandomNum;
39
40
  urlSplit: import("./types").IUrlSplit;
40
41
  urlJoin: import("./types").IUrlJoin;
@@ -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.indexOf(n)>0},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=t.prototype)&&void 0!==r?r: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},M=function(t){void 0===t&&(t={});var e=Object.create(null);return Reflect.ownKeys(t).forEach((function(n){return e[n]=t[n]})),e},L=function(t){void 0===t&&(t={});var e=M(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:M,isEmptyObject:L},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={arrayRandom:D,arrayUniq:B,arrayDemote:I},x=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([x],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([x],o,!1))}),e)}},R=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}},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,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},z={createElement:V},H=function(t,e,n){t.addEventListener?t.addEventListener(e,n,!1):t["on"+e]=n},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,n){t.removeEventListener?t.removeEventListener(e,n,!1):t["on"+e]=null},C=function(t,e){var n=new Event(e);t.dispatchEvent(n)},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,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")},Y=function(t){return X(t,!0,!1)},$=["\\","|","/","—","—"],tt=function(t){var e;void 0===t&&(t={});var n=t.loopList,r=void 0===n?$: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 Y("\n");l>=s-1&&(l=0);var f=r[l++];return Y(f),setTimeout((function(){t.index=l,tt(t)}),c),t},et={logOneLine:X,logLoop:tt},nt=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 rt(t,e,n){var r=1-n,o=n*n;return[2*r*n*t+o,2*r*n*e+o]}function ot(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 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 n=t.length-1,r=[0,0],o=0;o<=n;o++){var i=at(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 ut={AnimateFrame:nt,quadraticBezier:rt,cubicBezier:ot,factorial:it,combination:at,NBezier:ct},lt=n(n(n(n(n(n(n(n(n(n({},T),f),N),F),z),o),W),Q),et),ut);return t.AnimateFrame=nt,t.NBezier=ct,t.addHandler=H,t.arrayDemote=I,t.arrayRandom=D,t.arrayUniq=B,t.catchAwait=q,t.classDecorator=E,t.clearStorage=G,t.cloneDeep=m,t.combination=at,t.createElement=V,t.createObject=g,t.createObjectVariable=b,t.cubicBezier=ot,t.debounce=J,t.default=lt,t.defer=R,t.dispatchEvent=C,t.emptyObject=M,t.enumInversion=h,t.factorial=it,t.getInstance=j,t.getStorage=Z,t.getType=u,t.getTypeByList=l,t.getValue=p,t.inherit=w,t.isEmptyObject=L,t.isNotObject=y,t.isWindow=A,t.jsonToString=S,t.logLoop=tt,t.logOneLine=X,t.mixIn=d,t.quadraticBezier=rt,t.randomNum=i,t.removeHandler=_,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=U,t.setValue=v,t.stopBubble=K,t.stopDefault=P,t.stringToJson=O,t.throttle=k,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=t.prototype)&&void 0!==r?r: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){t.removeEventListener?t.removeEventListener(e,n,!1):t["on"+e]=null},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}({});
@@ -36,6 +36,10 @@ export type IRequestFrame = (callback: (start: number) => void, delay: number) =
36
36
  export type IArrayRandom<T extends any[]> = (arr: T) => T;
37
37
  export type IArrayUniq<T extends any[]> = (arr: T) => T;
38
38
  export type IArrayDemote<T extends IDemoteArray<any>> = (arr: T, result?: T) => T;
39
+ export type IArrayLoop = (list: unknown[], current?: number) => {
40
+ item: unknown;
41
+ current: number;
42
+ };
39
43
  type TagAttributes = Partial<Record<string, string | boolean>>;
40
44
  interface IElementParams<T> {
41
45
  ele: T | string;
@@ -1,10 +1,12 @@
1
- import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./types";
1
+ import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray, IArrayLoop } from "./types";
2
2
  export declare const arrayRandom: IArrayRandom<any[]>;
3
3
  export declare const arrayUniq: IArrayUniq<any[]>;
4
4
  export declare const arrayDemote: IArrayDemote<IDemoteArray<any>>;
5
+ export declare const arrayLoop: IArrayLoop;
5
6
  declare const _default: {
6
7
  arrayRandom: IArrayRandom<any[]>;
7
8
  arrayUniq: IArrayUniq<any[]>;
8
9
  arrayDemote: IArrayDemote<IDemoteArray<any>>;
10
+ arrayLoop: IArrayLoop;
9
11
  };
10
12
  export default _default;
@@ -35,6 +35,7 @@ declare const _default: {
35
35
  arrayRandom: import("./types").IArrayRandom<any[]>;
36
36
  arrayUniq: import("./types").IArrayUniq<any[]>;
37
37
  arrayDemote: import("./types").IArrayDemote<import("./types").IDemoteArray<any>>;
38
+ arrayLoop: import("./types").IArrayLoop;
38
39
  randomNum: import("./types").IRandomNum;
39
40
  urlSplit: import("./types").IUrlSplit;
40
41
  urlJoin: import("./types").IUrlJoin;
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.indexOf(r)>0},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=t.prototype)&&void 0!==n?n: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},b=function(t,e){return void 0===e&&(e=function(){}),e.prototype=x(t.prototype),e.prototype.super=t,e.prototype.constructor=e,e},g=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:b,getInstance:g,classDecorator:w,stringToJson:j,jsonToString:E,isWindow:O,emptyObject:S,isEmptyObject:A},T=function(t){return t.sort((function(){return Math.random()-.5}))},L=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={arrayRandom:T,arrayUniq:L,arrayDemote:D},I=void 0,N=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([I],o,!1)),n=null}),e))}},k=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([I],o,!1))}),e)}},J=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}},R=function(t){return t.then((function(t){return[null,t]})).catch((function(t){return[t]}))},q={throttle:N,debounce:k,defer:J,catchAwait:R},F=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},V={createElement:F},z=function(t,e,r){t.addEventListener?t.addEventListener(e,r,!1):t["on"+e]=r},H=function(t){(t=t||window.event).stopPropagation?t.stopPropagation():t.cancelBubble=!1},K=function(t){(t=t||window.event).preventDefault?t.preventDefault():t.returnValue=!1},P=function(t,e,r){t.removeEventListener?t.removeEventListener(e,r,!1):t["on"+e]=null},_=function(t,e){var r=new Event(e);t.dispatchEvent(r)},C={addHandler:z,stopBubble:H,stopDefault:K,removeHandler:P,dispatchEvent:_},W=function(t,e){try{localStorage.setItem(t,JSON.stringify(e))}catch(t){console.error(t)}},U=function(t){try{var e=localStorage.getItem(t);return null==e?null:JSON.parse(e)}catch(t){return console.error(t),null}},Z=function(t){try{t&&localStorage.removeItem(t),!t&&localStorage.clear()}catch(t){console.error(t)}},G={setStorage:W,getStorage:U,clearStorage:Z},Q=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")},X=function(t){return Q(t,!0,!1)},Y=["\\","|","/","—","—"],$=function(t){var e;void 0===t&&(t={});var r=t.loopList,n=void 0===r?Y: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 X("\n");s>=p-1&&(s=0);var l=n[s++];return X(l),setTimeout((function(){t.index=s,$(t)}),c),t},tt={logOneLine:Q,logLoop:$},et=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 rt(t,e,r){var n=1-r,o=r*r;return[2*n*r*t+o,2*n*r*e+o]}function nt(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 ot(t){return 0===t||1===t?1:t*ot(t-1)}function it(t,e){return ot(t)/(ot(e)*ot(t-e))}function at(t,e){for(var r=t.length-1,n=[0,0],o=0;o<=r;o++){var i=it(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 ct={AnimateFrame:et,quadraticBezier:rt,cubicBezier:nt,factorial:ot,combination:it,NBezier:at},ut=e(e(e(e(e(e(e(e(e(e({},M),p),B),q),V),n),C),G),tt),ct);exports.AnimateFrame=et,exports.NBezier=at,exports.addHandler=z,exports.arrayDemote=D,exports.arrayRandom=T,exports.arrayUniq=L,exports.catchAwait=R,exports.classDecorator=w,exports.clearStorage=Z,exports.cloneDeep=y,exports.combination=it,exports.createElement=F,exports.createObject=x,exports.createObjectVariable=m,exports.cubicBezier=nt,exports.debounce=k,exports.default=ut,exports.defer=J,exports.dispatchEvent=_,exports.emptyObject=S,exports.enumInversion=d,exports.factorial=ot,exports.getInstance=g,exports.getStorage=U,exports.getType=c,exports.getTypeByList=u,exports.getValue=l,exports.inherit=b,exports.isEmptyObject=A,exports.isNotObject=h,exports.isWindow=O,exports.jsonToString=E,exports.logLoop=$,exports.logOneLine=Q,exports.mixIn=v,exports.quadraticBezier=rt,exports.randomNum=o,exports.removeHandler=P,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=W,exports.setValue=f,exports.stopBubble=H,exports.stopDefault=K,exports.stringToJson=j,exports.throttle=N,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=t.prototype)&&void 0!==n?n: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){t.removeEventListener?t.removeEventListener(e,r,!1):t["on"+e]=null},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;
@@ -36,6 +36,10 @@ export type IRequestFrame = (callback: (start: number) => void, delay: number) =
36
36
  export type IArrayRandom<T extends any[]> = (arr: T) => T;
37
37
  export type IArrayUniq<T extends any[]> = (arr: T) => T;
38
38
  export type IArrayDemote<T extends IDemoteArray<any>> = (arr: T, result?: T) => T;
39
+ export type IArrayLoop = (list: unknown[], current?: number) => {
40
+ item: unknown;
41
+ current: number;
42
+ };
39
43
  type TagAttributes = Partial<Record<string, string | boolean>>;
40
44
  interface IElementParams<T> {
41
45
  ele: T | string;
@@ -1,10 +1,12 @@
1
- import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./types";
1
+ import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray, IArrayLoop } from "./types";
2
2
  export declare const arrayRandom: IArrayRandom<any[]>;
3
3
  export declare const arrayUniq: IArrayUniq<any[]>;
4
4
  export declare const arrayDemote: IArrayDemote<IDemoteArray<any>>;
5
+ export declare const arrayLoop: IArrayLoop;
5
6
  declare const _default: {
6
7
  arrayRandom: IArrayRandom<any[]>;
7
8
  arrayUniq: IArrayUniq<any[]>;
8
9
  arrayDemote: IArrayDemote<IDemoteArray<any>>;
10
+ arrayLoop: IArrayLoop;
9
11
  };
10
12
  export default _default;
@@ -35,6 +35,7 @@ declare const _default: {
35
35
  arrayRandom: import("./types").IArrayRandom<any[]>;
36
36
  arrayUniq: import("./types").IArrayUniq<any[]>;
37
37
  arrayDemote: import("./types").IArrayDemote<import("./types").IDemoteArray<any>>;
38
+ arrayLoop: import("./types").IArrayLoop;
38
39
  randomNum: import("./types").IRandomNum;
39
40
  urlSplit: import("./types").IUrlSplit;
40
41
  urlJoin: import("./types").IUrlJoin;
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.indexOf(e)>0},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=t.prototype)&&void 0!==r?r: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}},O=function(t){if(!u(t,["array","object","set","map"]))return"";try{return JSON.stringify(t)}catch(t){return""}},S=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:O,isWindow:S,emptyObject:M,isEmptyObject:A},T=function(t){return t.sort((function(){return Math.random()-.5}))},x=function(t){return Array.from(new Set(t))},k=function(t,n){return void 0===n&&(n=[]),t.forEach((function(t){return"array"===c(t)?k(t,n):n.push(t)})),n},D={arrayRandom:T,arrayUniq:x,arrayDemote:k},I=void 0,N=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([I],o,!1)),r=null}),n))}},R=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([I],o,!1))}),n)}},B=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}},J=function(t){return t.then((function(t){return[null,t]})).catch((function(t){return[t]}))},F=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}},q={throttle:N,debounce:R,defer:B,catchAwait:J},K=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},P={createElement:K},V=function(t,n,e){t.addEventListener?t.addEventListener(n,e,!1):t["on"+n]=e},z=function(t){(t=t||window.event).stopPropagation?t.stopPropagation():t.cancelBubble=!1},C=function(t){(t=t||window.event).preventDefault?t.preventDefault():t.returnValue=!1},H=function(t,n,e){t.removeEventListener?t.removeEventListener(n,e,!1):t["on"+n]=null},W=function(t,n){var e=new Event(n);t.dispatchEvent(e)},_={addHandler:V,stopBubble:z,stopDefault:C,removeHandler:H,dispatchEvent:W},U=function(t,n){try{localStorage.setItem(t,JSON.stringify(n))}catch(t){console.error(t)}},Z=function(t){try{var n=localStorage.getItem(t);return null==n?null:JSON.parse(n)}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,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")},Y=function(t){return X(t,!0,!1)},$=["\\","|","/","—","—"],tt=function(t){var n;void 0===t&&(t={});var e=t.loopList,r=void 0===e?$: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 Y("\n");f>=l-1&&(f=0);var s=r[f++];return Y(s),setTimeout((function(){t.index=f,tt(t)}),c),t},nt={logOneLine:X,logLoop:tt},et=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 rt(t,n,e){var r=1-e,o=e*e;return[2*r*e*t+o,2*r*e*n+o]}function ot(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 it(t){return 0===t||1===t?1:t*it(t-1)}function at(t,n){return it(t)/(it(n)*it(t-n))}function ct(t,n){for(var e=t.length-1,r=[0,0],o=0;o<=e;o++){var i=at(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 ut={AnimateFrame:et,quadraticBezier:rt,cubicBezier:ot,factorial:it,combination:at,NBezier:ct},ft=n(n(n(n(n(n(n(n(n(n({},L),l),D),q),P),r),_),Q),nt),ut);export{et as AnimateFrame,ct as NBezier,V as addHandler,k as arrayDemote,T as arrayRandom,x as arrayUniq,J as catchAwait,j as classDecorator,G as clearStorage,y as cloneDeep,at as combination,K as createElement,g as createObject,m as createObjectVariable,ot as cubicBezier,R as debounce,ft as default,B as defer,W as dispatchEvent,M as emptyObject,d as enumInversion,it as factorial,w as getInstance,Z as getStorage,c as getType,u as getTypeByList,s as getValue,b as inherit,A as isEmptyObject,h as isNotObject,S as isWindow,O as jsonToString,tt as logLoop,X as logOneLine,v as mixIn,rt as quadraticBezier,o as randomNum,H as removeHandler,F as requestFrame,U as setStorage,p as setValue,z as stopBubble,C as stopDefault,E as stringToJson,N 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=t.prototype)&&void 0!==r?r: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){t.removeEventListener?t.removeEventListener(n,e,!1):t["on"+n]=null},_=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};
@@ -36,6 +36,10 @@ export type IRequestFrame = (callback: (start: number) => void, delay: number) =
36
36
  export type IArrayRandom<T extends any[]> = (arr: T) => T;
37
37
  export type IArrayUniq<T extends any[]> = (arr: T) => T;
38
38
  export type IArrayDemote<T extends IDemoteArray<any>> = (arr: T, result?: T) => T;
39
+ export type IArrayLoop = (list: unknown[], current?: number) => {
40
+ item: unknown;
41
+ current: number;
42
+ };
39
43
  type TagAttributes = Partial<Record<string, string | boolean>>;
40
44
  interface IElementParams<T> {
41
45
  ele: T | string;
@@ -1,10 +1,12 @@
1
- import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray } from "./types";
1
+ import { IArrayRandom, IArrayUniq, IArrayDemote, IDemoteArray, IArrayLoop } from "./types";
2
2
  export declare const arrayRandom: IArrayRandom<any[]>;
3
3
  export declare const arrayUniq: IArrayUniq<any[]>;
4
4
  export declare const arrayDemote: IArrayDemote<IDemoteArray<any>>;
5
+ export declare const arrayLoop: IArrayLoop;
5
6
  declare const _default: {
6
7
  arrayRandom: IArrayRandom<any[]>;
7
8
  arrayUniq: IArrayUniq<any[]>;
8
9
  arrayDemote: IArrayDemote<IDemoteArray<any>>;
10
+ arrayLoop: IArrayLoop;
9
11
  };
10
12
  export default _default;
@@ -35,6 +35,7 @@ declare const _default: {
35
35
  arrayRandom: import("./types").IArrayRandom<any[]>;
36
36
  arrayUniq: import("./types").IArrayUniq<any[]>;
37
37
  arrayDemote: import("./types").IArrayDemote<import("./types").IDemoteArray<any>>;
38
+ arrayLoop: import("./types").IArrayLoop;
38
39
  randomNum: import("./types").IRandomNum;
39
40
  urlSplit: import("./types").IUrlSplit;
40
41
  urlJoin: import("./types").IUrlJoin;
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.indexOf(n)>0},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=t.prototype)&&void 0!==r?r: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},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},M=function(t){void 0===t&&(t={});var e=Object.create(null);return Reflect.ownKeys(t).forEach((function(n){return e[n]=t[n]})),e},T=function(t){void 0===t&&(t={});var e=M(t);return Reflect.ownKeys(e).length<=0},L={getValue:p,setValue:d,mixIn:v,enumInversion:h,isNotObject:y,cloneDeep:m,createObjectVariable:b,createObject:g,inherit:j,getInstance:w,classDecorator:E,stringToJson:O,jsonToString:S,isWindow:A,emptyObject:M,isEmptyObject:T},x=function(t){return t.sort((function(){return Math.random()-.5}))},D=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={arrayRandom:x,arrayUniq:D,arrayDemote: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,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}},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,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},z={createElement:V},H=function(t,e,n){t.addEventListener?t.addEventListener(e,n,!1):t["on"+e]=n},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,n){t.removeEventListener?t.removeEventListener(e,n,!1):t["on"+e]=null},C=function(t,e){var n=new Event(e);t.dispatchEvent(n)},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,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")},Y=function(t){return X(t,!0,!1)},$=["\\","|","/","—","—"],tt=function(t){var e;void 0===t&&(t={});var n=t.loopList,r=void 0===n?$: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 Y("\n");l>=s-1&&(l=0);var f=r[l++];return Y(f),setTimeout((function(){t.index=l,tt(t)}),c),t},et={logOneLine:X,logLoop:tt},nt=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 rt(t,e,n){var r=1-n,o=n*n;return[2*r*n*t+o,2*r*n*e+o]}function ot(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 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 n=t.length-1,r=[0,0],o=0;o<=n;o++){var i=at(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 ut={AnimateFrame:nt,quadraticBezier:rt,cubicBezier:ot,factorial:it,combination:at,NBezier:ct},lt=n(n(n(n(n(n(n(n(n(n({},L),f),I),F),z),o),W),Q),et),ut);t.AnimateFrame=nt,t.NBezier=ct,t.addHandler=H,t.arrayDemote=B,t.arrayRandom=x,t.arrayUniq=D,t.catchAwait=q,t.classDecorator=E,t.clearStorage=G,t.cloneDeep=m,t.combination=at,t.createElement=V,t.createObject=g,t.createObjectVariable=b,t.cubicBezier=ot,t.debounce=J,t.default=lt,t.defer=R,t.dispatchEvent=C,t.emptyObject=M,t.enumInversion=h,t.factorial=it,t.getInstance=w,t.getStorage=Z,t.getType=u,t.getTypeByList=l,t.getValue=p,t.inherit=j,t.isEmptyObject=T,t.isNotObject=y,t.isWindow=A,t.jsonToString=S,t.logLoop=tt,t.logOneLine=X,t.mixIn=v,t.quadraticBezier=rt,t.randomNum=i,t.removeHandler=_,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=U,t.setValue=d,t.stopBubble=K,t.stopDefault=P,t.stringToJson=O,t.throttle=k,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=t.prototype)&&void 0!==r?r: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},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:h,isNotObject:y,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){t.removeEventListener?t.removeEventListener(e,n,!1):t["on"+e]=null},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=h,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=y,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})}));
@@ -36,6 +36,10 @@ export type IRequestFrame = (callback: (start: number) => void, delay: number) =
36
36
  export type IArrayRandom<T extends any[]> = (arr: T) => T;
37
37
  export type IArrayUniq<T extends any[]> = (arr: T) => T;
38
38
  export type IArrayDemote<T extends IDemoteArray<any>> = (arr: T, result?: T) => T;
39
+ export type IArrayLoop = (list: unknown[], current?: number) => {
40
+ item: unknown;
41
+ current: number;
42
+ };
39
43
  type TagAttributes = Partial<Record<string, string | boolean>>;
40
44
  interface IElementParams<T> {
41
45
  ele: T | string;
package/package.json CHANGED
@@ -1,44 +1,44 @@
1
- {
2
- "name": "utils-lib-js-lite",
3
- "version": "1.0.0",
4
- "description": "JavaScript工具函数,封装的一些常用的js函数,轻量化工具包",
5
- "main": "./dist/cjs/index.js",
6
- "types": "./dist/cjs/index.d.ts",
7
- "module": "./dist/esm/index.js",
8
- "type": "module",
9
- "exports": {
10
- "import": "./dist/esm/index.js",
11
- "require": "./dist/cjs/index.js"
12
- },
13
- "scripts": {
14
- "debug": "start cmd /k pnpm run build:hot & pnpm run node:hot",
15
- "node:hot": "nodemon example.js --watch example.js",
16
- "build:hot": "pnpm rollup -c --watch",
17
- "build": "pnpm run rollup:build && pnpm run commonjs",
18
- "rollup:build": "rm -fr dist && pnpm rollup -c",
19
- "build:publish": "pnpm run build && pnpm publish",
20
- "commonjs": "cp ./commonjs.json dist/cjs/package.json"
21
- },
22
- "repository": {
23
- "type": "git",
24
- "url": "https://gitee.com/DieHunter/utils-lib-js.git"
25
- },
26
- "keywords": [
27
- "utils",
28
- "tools",
29
- "lib"
30
- ],
31
- "author": "",
32
- "license": "ISC",
33
- "devDependencies": {
34
- "@rollup/plugin-alias": "^4.0.3",
35
- "@rollup/plugin-node-resolve": "^15.0.1",
36
- "@rollup/plugin-typescript": "^11.0.0",
37
- "@types/node": "^18.7.15",
38
- "rollup": "^3.20.2",
39
- "rollup-plugin-terser": "^7.0.2",
40
- "tslib": "^2.5.0",
41
- "typescript": "^4.9.0"
42
- },
43
- "umdModuleName": "UtilsLib"
44
- }
1
+ {
2
+ "name": "utils-lib-js-lite",
3
+ "version": "1.1.0",
4
+ "description": "JavaScript工具函数,封装的一些常用的js函数,轻量化工具包",
5
+ "main": "./dist/cjs/index.js",
6
+ "types": "./dist/cjs/index.d.ts",
7
+ "module": "./dist/esm/index.js",
8
+ "type": "module",
9
+ "exports": {
10
+ "import": "./dist/esm/index.js",
11
+ "require": "./dist/cjs/index.js"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://gitee.com/DieHunter/utils-lib-js.git"
16
+ },
17
+ "keywords": [
18
+ "utils",
19
+ "tools",
20
+ "lib"
21
+ ],
22
+ "author": "",
23
+ "license": "ISC",
24
+ "devDependencies": {
25
+ "@rollup/plugin-alias": "^4.0.3",
26
+ "@rollup/plugin-node-resolve": "^15.0.1",
27
+ "@rollup/plugin-typescript": "^11.0.0",
28
+ "@types/node": "^18.7.15",
29
+ "rollup": "^3.20.2",
30
+ "rollup-plugin-terser": "^7.0.2",
31
+ "tslib": "^2.5.0",
32
+ "typescript": "^4.9.0"
33
+ },
34
+ "umdModuleName": "UtilsLib",
35
+ "scripts": {
36
+ "debug": "start cmd /k pnpm run build:hot & pnpm run node:hot",
37
+ "node:hot": "nodemon example.js --watch example.js",
38
+ "build:hot": "pnpm rollup -c --watch",
39
+ "build": "pnpm run rollup:build && pnpm run commonjs",
40
+ "rollup:build": "rm -fr dist && pnpm rollup -c",
41
+ "build:publish": "pnpm run build && pnpm publish",
42
+ "commonjs": "cp ./commonjs.json dist/cjs/package.json"
43
+ }
44
+ }