utils-lib-js 1.7.10 → 1.7.13
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 +28 -2
- package/README.md +28 -2
- package/dist/bundle/index.d.ts +1 -0
- package/dist/bundle/index.js +1 -6
- package/dist/bundle/object.d.ts +2 -0
- package/dist/bundle/request.d.ts +1 -2
- package/dist/bundle/types.d.ts +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +29 -983
- package/dist/cjs/object.d.ts +2 -0
- package/dist/cjs/request.d.ts +1 -2
- package/dist/cjs/types.d.ts +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +26 -981
- package/dist/esm/object.d.ts +2 -0
- package/dist/esm/request.d.ts +1 -2
- package/dist/esm/types.d.ts +1 -1
- package/dist/umd/index.d.ts +1 -0
- package/dist/umd/index.js +33 -983
- package/dist/umd/object.d.ts +2 -0
- package/dist/umd/request.d.ts +1 -2
- package/dist/umd/types.d.ts +1 -1
- package/package.json +1 -1
- package/pnpm-lock.yaml +3 -3
package/README.en.md
CHANGED
|
@@ -204,10 +204,10 @@ export type IDebounce = (fn: Function, time: number) => (...args: any[]) => void
|
|
|
204
204
|
|
|
205
205
|
/**
|
|
206
206
|
* Promise扁平化,避免Promise嵌套
|
|
207
|
+
* @param {number} timer 超时
|
|
207
208
|
* @returns {Promise,resolve,reject}
|
|
208
209
|
*/
|
|
209
|
-
|
|
210
|
-
export type IDefer = () => IPromise
|
|
210
|
+
export type IDefer = (timer: number) => IPromise
|
|
211
211
|
|
|
212
212
|
/**await与try catch 捕获异常处理方法
|
|
213
213
|
* @param {Promise<any>} defer 延迟函数
|
|
@@ -303,6 +303,31 @@ export type IRemoveHandler = <T extends Document>(ele: T, type: string, handler:
|
|
|
303
303
|
|
|
304
304
|
export type IDispatchEvent = <T extends Document>(ele: T, data: any) => void
|
|
305
305
|
|
|
306
|
+
|
|
307
|
+
##### log
|
|
308
|
+
|
|
309
|
+
/** 单行输出
|
|
310
|
+
* @param {string} str 输出字符
|
|
311
|
+
* @param {boolean} overwrite 覆盖前面的输出
|
|
312
|
+
* @param {boolean} warp 最后一行换行
|
|
313
|
+
* @return {void}
|
|
314
|
+
*/
|
|
315
|
+
export type ILogOneLine = (str: string, overwrite?: boolean, warp?: boolean) => void
|
|
316
|
+
|
|
317
|
+
/** 循环输出某个队列
|
|
318
|
+
* @param {string[]} loopList 输出的字符队列
|
|
319
|
+
* @param {number} index 第几个字符
|
|
320
|
+
* @param {boolean} isStop 控制暂停循环
|
|
321
|
+
* @param {number} timer 两个相隔时间间隔
|
|
322
|
+
*/
|
|
323
|
+
export type ILogLoopParams = {
|
|
324
|
+
loopList?: string[]
|
|
325
|
+
index?: number
|
|
326
|
+
isStop?: boolean
|
|
327
|
+
timer?: number
|
|
328
|
+
}
|
|
329
|
+
export type ILogLoop = (opts?: ILogLoopParams) => ILogLoopParams | void
|
|
330
|
+
|
|
306
331
|
##### request
|
|
307
332
|
|
|
308
333
|
export type IRequestParams<T> = T | IObject<any> | null
|
|
@@ -416,6 +441,7 @@ export declare interface IMessageCenter {
|
|
|
416
441
|
watch: (type: string, handler: Function) => this
|
|
417
442
|
invoke: (type: string, data?: any) => Promise<void>
|
|
418
443
|
}
|
|
444
|
+
|
|
419
445
|
https://gitee.com/DieHunter/message-center
|
|
420
446
|
|
|
421
447
|
<!-- 任务队列 -->
|
package/README.md
CHANGED
|
@@ -204,10 +204,10 @@ export type IDebounce = (fn: Function, time: number) => (...args: any[]) => void
|
|
|
204
204
|
|
|
205
205
|
/**
|
|
206
206
|
* Promise扁平化,避免Promise嵌套
|
|
207
|
+
* @param {number} timer 超时
|
|
207
208
|
* @returns {Promise,resolve,reject}
|
|
208
209
|
*/
|
|
209
|
-
|
|
210
|
-
export type IDefer = () => IPromise
|
|
210
|
+
export type IDefer = (timer: number) => IPromise
|
|
211
211
|
|
|
212
212
|
/**await与try catch 捕获异常处理方法
|
|
213
213
|
* @param {Promise<any>} defer 延迟函数
|
|
@@ -303,6 +303,31 @@ export type IRemoveHandler = <T extends Document>(ele: T, type: string, handler:
|
|
|
303
303
|
|
|
304
304
|
export type IDispatchEvent = <T extends Document>(ele: T, data: any) => void
|
|
305
305
|
|
|
306
|
+
|
|
307
|
+
##### log
|
|
308
|
+
|
|
309
|
+
/** 单行输出
|
|
310
|
+
* @param {string} str 输出字符
|
|
311
|
+
* @param {boolean} overwrite 覆盖前面的输出
|
|
312
|
+
* @param {boolean} warp 最后一行换行
|
|
313
|
+
* @return {void}
|
|
314
|
+
*/
|
|
315
|
+
export type ILogOneLine = (str: string, overwrite?: boolean, warp?: boolean) => void
|
|
316
|
+
|
|
317
|
+
/** 循环输出某个队列
|
|
318
|
+
* @param {string[]} loopList 输出的字符队列
|
|
319
|
+
* @param {number} index 第几个字符
|
|
320
|
+
* @param {boolean} isStop 控制暂停循环
|
|
321
|
+
* @param {number} timer 两个相隔时间间隔
|
|
322
|
+
*/
|
|
323
|
+
export type ILogLoopParams = {
|
|
324
|
+
loopList?: string[]
|
|
325
|
+
index?: number
|
|
326
|
+
isStop?: boolean
|
|
327
|
+
timer?: number
|
|
328
|
+
}
|
|
329
|
+
export type ILogLoop = (opts?: ILogLoopParams) => ILogLoopParams | void
|
|
330
|
+
|
|
306
331
|
##### request
|
|
307
332
|
|
|
308
333
|
export type IRequestParams<T> = T | IObject<any> | null
|
|
@@ -416,6 +441,7 @@ export declare interface IMessageCenter {
|
|
|
416
441
|
watch: (type: string, handler: Function) => this
|
|
417
442
|
invoke: (type: string, data?: any) => Promise<void>
|
|
418
443
|
}
|
|
444
|
+
|
|
419
445
|
https://gitee.com/DieHunter/message-center
|
|
420
446
|
|
|
421
447
|
<!-- 任务队列 -->
|
package/dist/bundle/index.d.ts
CHANGED
package/dist/bundle/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
var UtilsLib=function(e,t,n,r){"use strict";var o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},o(e,t)};function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var u=function(){return u=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},u.apply(this,arguments)};function a(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function c(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}var l,s=function(e,t,n){void 0===n&&(n="");for(var r=0,o=t.split(".");r<o.length;r++){if(void 0===(e=e[o[r]]))return n}return e},f=function(e,t,n){void 0===n&&(n={});for(var r=t.split("."),o=r[r.length-1],i=e,u=0,a=r;u<a.length;u++){var c=a[u];if("object"!=typeof i&&void 0!==i)return e;!i&&(i={}),!i[c]&&(i[c]={}),o===c&&(i[o]=n),i=i[c]}return e},p=function(e,t,n){var r;for(var o in void 0===t&&(t={}),void 0===n&&(n=!1),t)for(var i in t[o]){var u=null!==(r=e.prototype)&&void 0!==r?r:e;(void 0===e[i]||n)&&(u[i]=t[o][i])}return e},d=function(e){for(var t in e){var n=e[t];"string"!=typeof n||e[n]||(e[n]=t)}return e},h=function(e,t){return"object"!=typeof e||"null"===t},v=function(e){var t=x(e);if(h(e,t))return e;var n=y(t,e);return"map"===t?e.forEach((function(e,t){n.set(t,v(e))})):"set"===t?e.forEach((function(e){n.add(v(e))})):Reflect.ownKeys(e).forEach((function(t){var r=e[t];n[t]=v(r)})),n},y=function(e,t){switch(void 0===t&&(t={}),e){case"array":return[];case"function":return t;case"set":return new Set;case"map":return new Map;case"date":return new Date(t);case"regExp":return new RegExp(t);case"math":return Math;default:return{}}},g=function(e){function t(){}return t.prototype=e,new t},b=function(e,t){return void 0===t&&(t=function(){}),t.prototype=g(e.prototype),t.prototype.super=e,t.prototype.constructor=t,t},m=function(e,t){void 0===t&&(t=!1);for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return e._instance&&!t||(e._instance=new(e.bind.apply(e,c([void 0],n,!1)))),e._instance},w=function(e){return function(t){for(var n in e)Reflect.has(t.prototype,n)||(t.prototype[n]=e[n])}},j=function(e){if("string"!==x(e))return null;try{return JSON.parse(e)}catch(e){return null}},O=function(e){if(!q(e,["array","object","set","map"]))return"";try{return JSON.stringify(e)}catch(e){return""}},E={getValue:s,setValue:f,mixIn:p,enumInversion:d,isNotObject:h,cloneDeep:v,createObjectVariable:y,createObject:g,inherit:b,getInstance:m,classDecorator:w,stringToJson:j,jsonToString:O},T=function(e,t,n){return void 0===n&&(n=!1),Math.floor(Math.random()*(t-e+(n?1:0))+e)},P=function(e){var t={};return e.includes("?")?(e.split("?")[1].split("&").forEach((function(e){var n=e.split("=")[0];t[n]=e.split("=")[1]})),t):t},S=function(e,t){void 0===t&&(t={});var n=Object.keys(t);if(0===n.length)return e;var r=n.map((function(e){return"".concat(e,"=").concat(t[e])}));return"".concat(e).concat(e.includes("?")?"&":"?").concat(r.join("&"))},x=function(t){var n=typeof t;if(null===t)return"null";if("object"===n){var r=Object.prototype.toString.call(t);return e.types[r]}return n},q=function(e,t){void 0===t&&(t=[]);var n=x(e);return t.indexOf(n)>0},k={randomNum:T,urlSplit:P,urlJoin:S,getType:x,getTypeByList:q},D=function(e){return e.sort((function(){return Math.random()-.5}))},H=function(e){return Array.from(new Set(e))},L=function(e,t){return void 0===t&&(t=[]),e.forEach((function(e){return"array"===x(e)?L(e,t):t.push(e)})),t},A={arrayRandom:D,arrayUniq:H,arrayDemote:L},B=void 0,C=function(e,t){var n=null;return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];n||(n=setTimeout((function(){e.call.apply(e,c([B],r,!1)),n=null}),t))}},I=function(e,t){var n=null;return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];n&&(clearTimeout(n),n=null),n=setTimeout((function(){e.call.apply(e,c([B],r,!1))}),t)}},M=function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),resolve:e,reject:t}},_=function(e){return e.then((function(e){return[null,e]})).catch((function(e){return[e]}))},R={throttle:C,debounce:I,defer:M,catchAwait:_},F=function(e){var t,n,r=e.ele,o=e.style,i=e.attr,u=e.parent,a=r instanceof HTMLElement?r:document.createElement(null!=r?r:"div");return o&&(null===(t=Object.keys(o))||void 0===t||t.forEach((function(e){return a.style[e]=o[e]}))),i&&(null===(n=Object.keys(o))||void 0===n||n.forEach((function(e){return a[e]=i[e]}))),u&&u.appendChild(a),a},N={createElement:F};e.types=void 0,(l=e.types||(e.types={}))["[object Array]"]="array",l["[object Object]"]="object",l["[object Function]"]="function",l["[object Set]"]="set",l["[object Map]"]="map",l["[object WeakMap]"]="weakMap",l["[object WeakSet]"]="weakSet",l["[object Date]"]="date",l["[object RegExp]"]="regExp",l["[object Math]"]="math";var W={types:e.types};
|
|
2
|
-
/**
|
|
3
|
-
* @author Toru Nagashima <https://github.com/mysticatea>
|
|
4
|
-
* @copyright 2015 Toru Nagashima. All rights reserved.
|
|
5
|
-
* See LICENSE file in root directory for full license.
|
|
6
|
-
*/const U=new WeakMap,V=new WeakMap;function G(e){const t=U.get(e);return console.assert(null!=t,"'this' is expected an Event object, but got",e),t}function J(e){null==e.passiveListener?e.event.cancelable&&(e.canceled=!0,"function"==typeof e.event.preventDefault&&e.event.preventDefault()):"undefined"!=typeof console&&"function"==typeof console.error&&console.error("Unable to preventDefault inside passive event listener invocation.",e.passiveListener)}function Q(e,t){U.set(this,{eventTarget:e,event:t,eventPhase:2,currentTarget:e,canceled:!1,stopped:!1,immediateStopped:!1,passiveListener:null,timeStamp:t.timeStamp||Date.now()}),Object.defineProperty(this,"isTrusted",{value:!1,enumerable:!0});const n=Object.keys(t);for(let e=0;e<n.length;++e){const t=n[e];t in this||Object.defineProperty(this,t,$(t))}}function $(e){return{get(){return G(this).event[e]},set(t){G(this).event[e]=t},configurable:!0,enumerable:!0}}function K(e){return{value(){const t=G(this).event;return t[e].apply(t,arguments)},configurable:!0,enumerable:!0}}function z(e){if(null==e||e===Object.prototype)return Q;let t=V.get(e);return null==t&&(t=function(e,t){const n=Object.keys(t);if(0===n.length)return e;function r(t,n){e.call(this,t,n)}r.prototype=Object.create(e.prototype,{constructor:{value:r,configurable:!0,writable:!0}});for(let o=0;o<n.length;++o){const i=n[o];if(!(i in e.prototype)){const e="function"==typeof Object.getOwnPropertyDescriptor(t,i).value;Object.defineProperty(r.prototype,i,e?K(i):$(i))}}return r}(z(Object.getPrototypeOf(e)),e),V.set(e,t)),t}function X(e){return G(e).immediateStopped}function Y(e,t){G(e).passiveListener=t}Q.prototype={get type(){return G(this).event.type},get target(){return G(this).eventTarget},get currentTarget(){return G(this).currentTarget},composedPath(){const e=G(this).currentTarget;return null==e?[]:[e]},get NONE(){return 0},get CAPTURING_PHASE(){return 1},get AT_TARGET(){return 2},get BUBBLING_PHASE(){return 3},get eventPhase(){return G(this).eventPhase},stopPropagation(){const e=G(this);e.stopped=!0,"function"==typeof e.event.stopPropagation&&e.event.stopPropagation()},stopImmediatePropagation(){const e=G(this);e.stopped=!0,e.immediateStopped=!0,"function"==typeof e.event.stopImmediatePropagation&&e.event.stopImmediatePropagation()},get bubbles(){return Boolean(G(this).event.bubbles)},get cancelable(){return Boolean(G(this).event.cancelable)},preventDefault(){J(G(this))},get defaultPrevented(){return G(this).canceled},get composed(){return Boolean(G(this).event.composed)},get timeStamp(){return G(this).timeStamp},get srcElement(){return G(this).eventTarget},get cancelBubble(){return G(this).stopped},set cancelBubble(e){if(!e)return;const t=G(this);t.stopped=!0,"boolean"==typeof t.event.cancelBubble&&(t.event.cancelBubble=!0)},get returnValue(){return!G(this).canceled},set returnValue(e){e||J(G(this))},initEvent(){}},Object.defineProperty(Q.prototype,"constructor",{value:Q,configurable:!0,writable:!0}),"undefined"!=typeof window&&void 0!==window.Event&&(Object.setPrototypeOf(Q.prototype,window.Event.prototype),V.set(window.Event.prototype,Q));const Z=new WeakMap,ee=3;function te(e){return null!==e&&"object"==typeof e}function ne(e){const t=Z.get(e);if(null==t)throw new TypeError("'this' is expected an EventTarget object, but got another value.");return t}function re(e,t){Object.defineProperty(e,`on${t}`,function(e){return{get(){let t=ne(this).get(e);for(;null!=t;){if(t.listenerType===ee)return t.listener;t=t.next}return null},set(t){"function"==typeof t||te(t)||(t=null);const n=ne(this);let r=null,o=n.get(e);for(;null!=o;)o.listenerType===ee?null!==r?r.next=o.next:null!==o.next?n.set(e,o.next):n.delete(e):r=o,o=o.next;if(null!==t){const o={listener:t,listenerType:ee,passive:!1,once:!1,next:null};null===r?n.set(e,o):r.next=o}},configurable:!0,enumerable:!0}}(t))}function oe(e){function t(){ie.call(this)}t.prototype=Object.create(ie.prototype,{constructor:{value:t,configurable:!0,writable:!0}});for(let n=0;n<e.length;++n)re(t.prototype,e[n]);return t}function ie(){if(!(this instanceof ie)){if(1===arguments.length&&Array.isArray(arguments[0]))return oe(arguments[0]);if(arguments.length>0){const e=new Array(arguments.length);for(let t=0;t<arguments.length;++t)e[t]=arguments[t];return oe(e)}throw new TypeError("Cannot call a class as a function")}Z.set(this,new Map)}ie.prototype={addEventListener(e,t,n){if(null==t)return;if("function"!=typeof t&&!te(t))throw new TypeError("'listener' should be a function or an object.");const r=ne(this),o=te(n),i=(o?Boolean(n.capture):Boolean(n))?1:2,u={listener:t,listenerType:i,passive:o&&Boolean(n.passive),once:o&&Boolean(n.once),next:null};let a=r.get(e);if(void 0===a)return void r.set(e,u);let c=null;for(;null!=a;){if(a.listener===t&&a.listenerType===i)return;c=a,a=a.next}c.next=u},removeEventListener(e,t,n){if(null==t)return;const r=ne(this),o=(te(n)?Boolean(n.capture):Boolean(n))?1:2;let i=null,u=r.get(e);for(;null!=u;){if(u.listener===t&&u.listenerType===o)return void(null!==i?i.next=u.next:null!==u.next?r.set(e,u.next):r.delete(e));i=u,u=u.next}},dispatchEvent(e){if(null==e||"string"!=typeof e.type)throw new TypeError('"event.type" should be a string.');const t=ne(this),n=e.type;let r=t.get(n);if(null==r)return!0;const o=function(e,t){return new(z(Object.getPrototypeOf(t)))(e,t)}(this,e);let i=null;for(;null!=r;){if(r.once?null!==i?i.next=r.next:null!==r.next?t.set(n,r.next):t.delete(n):i=r,Y(o,r.passive?r.listener:null),"function"==typeof r.listener)try{r.listener.call(this,o)}catch(e){"undefined"!=typeof console&&"function"==typeof console.error&&console.error(e)}else r.listenerType!==ee&&"function"==typeof r.listener.handleEvent&&r.listener.handleEvent(o);if(X(o))break;r=r.next}return Y(o,null),function(e,t){G(e).eventPhase=t}(o,0),function(e,t){G(e).currentTarget=t}(o,null),!o.defaultPrevented}},Object.defineProperty(ie.prototype,"constructor",{value:ie,configurable:!0,writable:!0}),"undefined"!=typeof window&&void 0!==window.EventTarget&&Object.setPrototypeOf(ie.prototype,window.EventTarget.prototype);class ue extends ie{constructor(){throw super(),new TypeError("AbortSignal cannot be constructed directly")}get aborted(){const e=ae.get(this);if("boolean"!=typeof e)throw new TypeError("Expected 'this' to be an 'AbortSignal' object, but got "+(null===this?"null":typeof this));return e}}re(ue.prototype,"abort");const ae=new WeakMap;Object.defineProperties(ue.prototype,{aborted:{enumerable:!0}}),"function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(ue.prototype,Symbol.toStringTag,{configurable:!0,value:"AbortSignal"});class ce{constructor(){le.set(this,function(){const e=Object.create(ue.prototype);return ie.call(e),ae.set(e,!1),e}())}get signal(){return se(this)}abort(){var e;e=se(this),!1===ae.get(e)&&(ae.set(e,!0),e.dispatchEvent({type:"abort"}))}}const le=new WeakMap;function se(e){const t=le.get(e);if(null==t)throw new TypeError("Expected 'this' to be an 'AbortController' object, but got "+(null===e?"null":typeof e));return t}Object.defineProperties(ce.prototype,{signal:{enumerable:!0},abort:{enumerable:!0}}),"function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(ce.prototype,Symbol.toStringTag,{configurable:!0,value:"AbortController"});var fe=function(e){function t(t){var n=e.call(this)||this;return n.chackUrl=function(e){return e.startsWith("/")},n.checkIsHttps=function(e){return e.startsWith("https")},n.fixOrigin=function(e){return n.chackUrl(e)?n.origin+e:e},n.envDesc=function(){return"undefined"!=typeof Window?"Window":"Node"},n.errorFn=function(e){return function(t){var r,o;return e(null!==(o=null===(r=n.errFn)||void 0===r?void 0:r.call(n,t))&&void 0!==o?o:t)}},n.clearTimer=function(e){return!!e.timer&&(clearTimeout(e.timer),e.timer=null)},n.initAbort=function(e){var t=e.controller,n=e.timer,r=e.timeout;return!n&&(e.timer=setTimeout((function(){return t.abort()}),r)),e},n.requestType=function(){switch(n.envDesc()){case"Window":return n.fetch;case"Node":return n.http}},n.getDataByType=function(e,t){switch(e){case"text":case"json":case"blob":case"formData":case"arrayBuffer":return t[e]();default:return t.json()}},n.formatBodyString=function(e){return{text:function(){return e},json:function(){var t;return null!==(t=j(e))&&void 0!==t?t:e},blob:function(){return j(e)},formData:function(){return j(e)},arrayBuffer:function(){return j(e)}}},n.origin=null!=t?t:"",n}return i(t,e),t}(function(){function e(){}return e.prototype.use=function(e,t){switch(e){case"request":this.requestSuccess=t;break;case"response":this.responseSuccess=t;break;case"error":this.error=t}return this},Object.defineProperty(e.prototype,"reqFn",{get:function(){return this.requestSuccess},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"resFn",{get:function(){return this.responseSuccess},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"errFn",{get:function(){return this.error},enumerable:!1,configurable:!0}),e}()),pe=function(e){function t(t){var n=e.call(this,t)||this;return n.initDefaultParams=function(e,t){var r,o,i=t.method,c=void 0===i?"GET":i,l=t.query,s=void 0===l?{}:l,f=t.headers,p=void 0===f?{}:f,d=t.body,h=void 0===d?null:d,v=t.timeout,y=void 0===v?3e4:v,g=t.controller,b=void 0===g?new ce:g,m=t.type,w=void 0===m?"json":m,j=a(t,["method","query","headers","body","timeout","controller","type"]),E=u({url:e,method:c,query:s,headers:p,body:"GET"===c?null:O(h),timeout:y,signal:null==b?void 0:b.signal,controller:b,type:w,timer:null},j),T=null!==(o=null===(r=n.reqFn)||void 0===r?void 0:r.call(n,E))&&void 0!==o?o:E;return T.url=S(n.fixOrigin(e),E.query),T},n.initFetchParams=function(e,t){return n.initAbort(n.initDefaultParams(e,t))},n.initHttpParams=function(e,t){var o=n.initAbort(n.initDefaultParams(e,t)),i=r.parse(o.url,!0);return u(u({},o),i)},n}return i(t,e),t}(fe),de=function(e){function r(r){var o=e.call(this,r)||this;return o.fetch=function(e,t){var n=M(),r=n.promise,i=n.resolve,u=n.reject,c=o.initFetchParams(e,t),l=c.url,s=a(c,["url"]),f=s.signal;return r.finally((function(){return o.clearTimer(s)})),f.addEventListener("abort",(function(){return o.errorFn(u)})),fetch(l,s).then((function(e){return(null==e?void 0:e.status)>=200&&(null==e?void 0:e.status)<300?o.getDataByType(s.type,e):o.errorFn(u)})).then((function(e){var t,n;return i(null!==(n=null===(t=o.resFn)||void 0===t?void 0:t.call(o,e))&&void 0!==n?n:e)})).catch(o.errorFn(u)),r},o.http=function(e,r){var i=M(),u=i.promise,a=i.resolve,c=i.reject,l=o.initHttpParams(e,r),s=l.signal,f=l.url;u.finally((function(){return o.clearTimer(l)}));var p=(o.checkIsHttps(f)?n.request:t.request)(l,(function(e){if((null==e?void 0:e.statusCode)>=200&&(null==e?void 0:e.statusCode)<300){var t="";return e.setEncoding("utf8"),e.on("data",(function(e){return t+=e})),e.on("end",(function(){var e,n,r=o.getDataByType(l.type,o.formatBodyString(t));a(null!==(n=null===(e=o.resFn)||void 0===e?void 0:e.call(o,r))&&void 0!==n?n:r)}))}return o.errorFn(c)(null==e?void 0:e.statusMessage)}));return s.addEventListener("abort",(function(){return o.errorFn(c)(p.destroy(new Error("request timeout")))})),p.on("error",o.errorFn(c)),p.end(),u},o.GET=function(e,t,n,r){return o.request(e,u({query:t,method:"GET"},r))},o.POST=function(e,t,n,r){return o.request(e,u({query:t,method:"POST",body:n},r))},o.PUT=function(e,t,n,r){return o.request(e,u({query:t,method:"PUT",body:n},r))},o.DELETE=function(e,t,n,r){return o.request(e,u({query:t,method:"DELETE",body:n},r))},o.OPTIONS=function(e,t,n,r){return o.request(e,u({query:t,method:"OPTIONS",body:n},r))},o.HEAD=function(e,t,n,r){return o.request(e,u({query:t,method:"HEAD",body:n},r))},o.PATCH=function(e,t,n,r){return o.request(e,u({query:t,method:"PATCH",body:n},r))},o.request=o.requestType(),o}return i(r,e),r}(pe),he={Request:de},ve=function(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e["on"+t]=n},ye=function(e){(e=e||window.event).stopPropagation?e.stopPropagation():e.cancelBubble=!1},ge=function(e){(e=e||window.event).preventDefault?e.preventDefault():e.returnValue=!1},be=function(e,t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e["on"+t]=null},me=function(e,t){var n=new Event(t);e.dispatchEvent(n)},we={addHandler:ve,stopBubble:ye,stopDefault:ge,removeHandler:be,dispatchEvent:me},je=function(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(e){console.error(e)}},Oe=function(e){try{var t=localStorage.getItem(e);return null==t?null:JSON.parse(t)}catch(e){return console.error(e),null}},Ee=function(e){try{e&&localStorage.removeItem(e),!e&&localStorage.clear()}catch(e){console.error(e)}},Te={setStorage:je,getStorage:Oe,clearStorage:Ee},Pe=function(e,t,n){void 0===t&&(t=!1),void 0===n&&(n=!0),t&&(process.stdout.clearLine(0),process.stdout.cursorTo(0)),process.stdout.write(e),n&&process.stdout.write("\n")},Se=function(e){return Pe(e,!0,!1)},xe=["\\","|","/","—","—"],qe=function(e){var t;void 0===e&&(e={});var n=e.loopList,r=void 0===n?xe:n,o=e.isStop,i=void 0!==o&&o,u=e.timer,a=void 0===u?100:u,c=e.index,l=void 0===c?0:c,s=null!==(t=null==r?void 0:r.length)&&void 0!==t?t:0;if(!s)return e;if(i)return Se("\n");l>=s-1&&(l=0);var f=r[l++];return Se(f),setTimeout((function(){e.index=l,qe(e)}),a),e},ke={logOneLine:Pe,logLoop:qe},De=function(){function e(e){void 0===e&&(e={}),this.options=e,this.events={}}return e.prototype.on=function(e,t){return this.checkHandler(e,t),this.getHandler(e,[]).push(t),this},e.prototype.emit=function(e,t){return this.has(e)&&this.runHandler(e,t),this},e.prototype.un=function(e,t){return this.unHandler(e,t),this},e.prototype.once=function(e,t){var n=this;this.checkHandler(e,t);var r=function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];return n.un(e,r),t.apply(void 0,o)};return this.on(e,r),this},e.prototype.clear=function(){return this.events={},this},e.prototype.has=function(e){return!!this.getHandler(e)},e.prototype.getHandler=function(e,t){var n;return"object"==typeof t&&(this.events[e]=null!==(n=this.events[e])&&void 0!==n?n:t),this.events[e]},e.prototype.handlerLength=function(e){var t,n;return null!==(n=null===(t=this.getHandler(e))||void 0===t?void 0:t.length)&&void 0!==n?n:0},e.prototype.watch=function(e,t){var n=this;this.checkHandler(e,t);return this.on(e,(function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];n.emit(n.prefixStr(e),t.apply(void 0,r))})),this},e.prototype.invoke=function(e,t){var n=this;return new Promise((function(r){n.once(n.prefixStr(e),r),n.emit(e,t)}))},e.prototype.runHandler=function(e,t){for(var n=0,r=this.getHandler(e);n<r.length;n++){var o=r[n];o&&o(t)}},e.prototype.unHandler=function(e,t){var n=this.getHandler(e);!t&&(this.events[e]=[]),t&&this.checkHandler(e,t);for(var r=0;r<n.length;r++)n&&n[r]===t&&(n[r]=null)},e.prototype.prefixStr=function(e){return"@".concat(e)},e.prototype.checkHandler=function(e,t){var n=this.options,r=n.blackList,o=void 0===r?[]:r,i=n.maxLen,u=void 0===i?1/0:i,a=this.handlerLength(e);if(0===(null==e?void 0:e.length))throw new Error("type.length can not be 0");if(!t||!e)throw new ReferenceError("type or handler is not defined");if("function"!=typeof t||"string"!=typeof e)throw new TypeError("".concat(t," is not a function or ").concat(e," is not a string"));if(o.includes(e))throw new Error("".concat(e," is not allow"));if(u<=a)throw new Error("the number of ".concat(e," must be less than ").concat(u))},e.Instance=function(e){return e._instance||Object.defineProperty(e,"_instance",{value:new e}),e._instance},e}(),He=De.Instance(De),Le=function(e){return e.prototype.messageCenter||(e.prototype.messageCenter=new De),e},Ae=function(){return Ae=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},Ae.apply(this,arguments)},Be=function(e,t,n,r){var o,i=arguments.length,u=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(u=(i<3?o(u):i>3?o(t,n,u):o(t,n))||u);return i>3&&u&&Object.defineProperty(t,n,u),u},Ce=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},Ie=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,a)}c((r=r.apply(e,t||[])).next())}))},Me=function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},_e=function(){function e(e){var t=this;this.fix="@~&$",this.init=function(){t.messageCenter.on("push:handler",t.run),t.messageCenter.on("run:success:handler",t.run),t.messageCenter.on("run:success:handler",t.finish),t.messageCenter.on("run:error:handler",t.run),t.messageCenter.on("run:error:handler",t.finish)},this.defineProps=function(e,n){Object.defineProperty(t,n,{value:e})},this.push=function(e){var n;t.checkHandler(e);var r=(n=t.defer()).resolve,o=n.reject,i=n.promise,u=t.fixStr(e.name);return t.queues=t.queues.concat(e.children.map((function(e){return{defer:e,name:u}}))),t.queueTemp[u]=Ae(Ae({},e),{result:[]}),t.messageCenter.emit("push:handler",o),t.messageCenter.on(u,r),i},this.unshift=function(e){return t.queues.splice(0,e)},this.run=function(e){var n=e.reject;return Ie(t,void 0,void 0,(function(){var e,t,r,o,i;return Me(this,(function(u){switch(u.label){case 0:if("pending"===this.stateProxy())return[2,void 0];if(0===this.queues.length)return[2,this.stateProxy("idle")];this.stateProxy("pending"),e=this.unshift(null!==(i=null===(o=this.props)||void 0===o?void 0:o.maxLen)&&void 0!==i?i:10),u.label=1;case 1:return u.trys.push([1,3,,4]),[4,Promise.all(e.map((function(e,t){return e.defer().catch((function(e){return e}))})))];case 2:return t=u.sent(),[2,this.handlerSuccess({res:t,queues:e})];case 3:return r=u.sent(),[2,this.handlerError({reject:n,error:r,queues:e})];case 4:return[2]}}))}))},this.clear=function(){t.queues=[],t.queueTemp={},t.props=null,t.stateProxy("idle"),t.messageCenter.clear()},this.finish=function(e){var n=e.res,r=void 0===n?[]:n,o=e.queues,i=e.error,u=void 0===i?"err":i,a=t.queueTemp;o.forEach((function(e,n){var o,i,c,l=a[e.name];null==l||l.result.push(null!==(o=r[n])&&void 0!==o?o:u),(null===(i=null==l?void 0:l.result)||void 0===i?void 0:i.length)===(null===(c=null==l?void 0:l.children)||void 0===c?void 0:c.length)&&(t.messageCenter.emit(e.name,null==l?void 0:l.result),a[e.name]=null)}))},this.handlerSuccess=function(e){return t.stateProxy("fulfilled"),t.messageCenter.emit("run:success:handler",e)},this.handlerError=function(e){var n=e.reject,r=e.error;return t.stateProxy("rejected"),n&&"function"==typeof n&&n(r),t.messageCenter.emit("run:error:handler",e)},this.stateProxy=function(e){return e&&(t.state=e),t.state},this.defer=function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),resolve:e,reject:t}},this.clear(),e&&this.defineProps(e,"props"),this.init()}return e.prototype.checkHandler=function(e){var t,n;if(!e)throw new ReferenceError("queue is not defined");if(!(e.children instanceof Array)||"object"!=typeof e)throw new TypeError("queue should be an object and queue.children should be an array");if(0===(null===(t=e.children)||void 0===t?void 0:t.length))throw new Error("queue.children.length can not be 0");if(null===(n=e.children)||void 0===n?void 0:n.find((function(e){return function(e){return!e||"function"!=typeof e}(e)})))throw new Error("queueList should have defer")},e.prototype.fixStr=function(e){return"".concat(this.fix).concat(e)},e=Be([Le,Ce("design:paramtypes",[Object])],e)}(),Re=u(u(u(u(u(u(u(u(u(u(u({},E),k),A),R),N),W),he),we),Te),ke),{eventMessageCenter:De,taskQueueLib:_e});return e.MessageCenter=De,e.Request=de,e.TaskQueue=_e,e.addHandler=ve,e.arrayDemote=L,e.arrayRandom=D,e.arrayUniq=H,e.catchAwait=_,e.classDecorator=w,e.clearStorage=Ee,e.cloneDeep=v,e.createElement=F,e.createObject=g,e.createObjectVariable=y,e.debounce=I,e.decoratorMessageCenter=Le,e.decoratorTaskQueue=function(e){return function(t){t.prototype.taskQueue||(t.prototype.taskQueue=new _e(e))}},e.default=Re,e.defer=M,e.dispatchEvent=me,e.enumInversion=d,e.getInstance=m,e.getStorage=Oe,e.getType=x,e.getTypeByList=q,e.getValue=s,e.inherit=b,e.isNotObject=h,e.jsonToString=O,e.logLoop=qe,e.logOneLine=Pe,e.messageCenter=He,e.mixIn=p,e.randomNum=T,e.removeHandler=be,e.setStorage=je,e.setValue=f,e.stopBubble=ye,e.stopDefault=ge,e.stringToJson=j,e.throttle=C,e.urlJoin=S,e.urlSplit=P,Object.defineProperty(e,"__esModule",{value:!0}),e}({},http,https,url);
|
|
1
|
+
var UtilsLib=function(e){"use strict";var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)};function n(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},r.apply(this,arguments)};function o(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}function i(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}var u,a=function(e,t,n){void 0===n&&(n="");for(var r=0,o=t.split(".");r<o.length;r++){if(void 0===(e=e[o[r]]))return n}return e},c=function(e,t,n){void 0===n&&(n={});for(var r=t.split("."),o=r[r.length-1],i=e,u=0,a=r;u<a.length;u++){var c=a[u];if("object"!=typeof i&&void 0!==i)return e;!i&&(i={}),!i[c]&&(i[c]={}),o===c&&(i[o]=n),i=i[c]}return e},s=function(e,t,n){var r;for(var o in void 0===t&&(t={}),void 0===n&&(n=!1),t)for(var i in t[o]){var u=null!==(r=e.prototype)&&void 0!==r?r:e;(void 0===e[i]||n)&&(u[i]=t[o][i])}return e},l=function(e){for(var t in e){var n=e[t];"string"!=typeof n||e[n]||(e[n]=t)}return e},f=function(e,t){return"object"!=typeof e||"null"===t},p=function(e){var t=T(e);if(f(e,t))return e;var n=d(t,e);return"map"===t?e.forEach((function(e,t){n.set(t,p(e))})):"set"===t?e.forEach((function(e){n.add(p(e))})):Reflect.ownKeys(e).forEach((function(t){var r=e[t];n[t]=p(r)})),n},d=function(e,t){switch(void 0===t&&(t={}),e){case"array":return[];case"function":return t;case"set":return new Set;case"map":return new Map;case"date":return new Date(t);case"regExp":return new RegExp(t);case"math":return Math;default:return{}}},h=function(e){function t(){}return t.prototype=e,new t},v=function(e,t){return void 0===t&&(t=function(){}),t.prototype=h(e.prototype),t.prototype.super=e,t.prototype.constructor=t,t},y=function(e,t){void 0===t&&(t=!1);for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return e._instance&&!t||(e._instance=new(e.bind.apply(e,i([void 0],n,!1)))),e._instance},m=function(e){return function(t){for(var n in e)Reflect.has(t.prototype,n)||(t.prototype[n]=e[n])}},g=function(e){if("string"!==T(e))return null;try{return JSON.parse(e)}catch(e){return null}},b=function(e){if(!S(e,["array","object","set","map"]))return"";try{return JSON.stringify(e)}catch(e){return""}},w=function(e){return e&&e===e.window},j={getValue:a,setValue:c,mixIn:s,enumInversion:l,isNotObject:f,cloneDeep:p,createObjectVariable:d,createObject:h,inherit:v,getInstance:y,classDecorator:m,stringToJson:g,jsonToString:b,isWindow:w},O=function(e,t,n){return void 0===n&&(n=!1),Math.floor(Math.random()*(t-e+(n?1:0))+e)},E=function(e){var t={};return e.includes("?")?(e.split("?")[1].split("&").forEach((function(e){var n=e.split("=")[0];t[n]=e.split("=")[1]})),t):t},q=function(e,t){void 0===t&&(t={});var n=Object.keys(t);if(0===n.length)return e;var r=n.map((function(e){return"".concat(e,"=").concat(t[e])}));return"".concat(e).concat(e.includes("?")?"&":"?").concat(r.join("&"))},T=function(t){var n=typeof t;if(null===t)return"null";if("object"===n){var r=Object.prototype.toString.call(t);return e.types[r]}return n},S=function(e,t){void 0===t&&(t=[]);var n=T(e);return t.indexOf(n)>0},P={randomNum:O,urlSplit:E,urlJoin:q,getType:T,getTypeByList:S},x=function(e){return e.sort((function(){return Math.random()-.5}))},k=function(e){return Array.from(new Set(e))},H=function(e,t){return void 0===t&&(t=[]),e.forEach((function(e){return"array"===T(e)?H(e,t):t.push(e)})),t},D={arrayRandom:x,arrayUniq:k,arrayDemote:H},C=void 0,L=function(e,t){var n=null;return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];n||(n=setTimeout((function(){e.call.apply(e,i([C],r,!1)),n=null}),t))}},A=function(e,t){var n=null;return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];n&&(clearTimeout(n),n=null),n=setTimeout((function(){e.call.apply(e,i([C],r,!1))}),t)}},F=function(e){var t,n;return void 0===e&&(e=0),e>0&&setTimeout(n,e),{promise:new Promise((function(e,r){t=e,n=r})),resolve:t,reject:n}},I=function(e){return e.then((function(e){return[null,e]})).catch((function(e){return[e]}))},R={throttle:L,debounce:A,defer:F,catchAwait:I},_=function(e){var t,n,r=e.ele,o=e.style,i=e.attr,u=e.parent,a=r instanceof HTMLElement?r:document.createElement(null!=r?r:"div");return o&&(null===(t=Object.keys(o))||void 0===t||t.forEach((function(e){return a.style[e]=o[e]}))),i&&(null===(n=Object.keys(o))||void 0===n||n.forEach((function(e){return a[e]=i[e]}))),u&&u.appendChild(a),a},M={createElement:_};e.types=void 0,(u=e.types||(e.types={}))["[object Array]"]="array",u["[object Object]"]="object",u["[object Function]"]="function",u["[object Set]"]="set",u["[object Map]"]="map",u["[object WeakMap]"]="weakMap",u["[object WeakSet]"]="weakSet",u["[object Date]"]="date",u["[object RegExp]"]="regExp",u["[object Math]"]="math";var B,N,W,J,U={types:e.types};"undefined"!=typeof require?(J=require("abort-controller"),B=require("http").request,N=require("https").request,W=require("url").parse):J="undefined"!=typeof AbortController?AbortController:function(){throw new Error("AbortController is not defined")};var V=function(e){function t(t){var n=e.call(this)||this;return n.chackUrl=function(e){return e.startsWith("/")},n.checkIsHttps=function(e){return e.startsWith("https")},n.fixOrigin=function(e){return n.chackUrl(e)?n.origin+e:e},n.envDesc=function(){return"undefined"!=typeof Window?"Window":"Node"},n.errorFn=function(e){return function(t){var r,o;return e(null!==(o=null===(r=n.errFn)||void 0===r?void 0:r.call(n,t))&&void 0!==o?o:t)}},n.clearTimer=function(e){return!!e.timer&&(clearTimeout(e.timer),e.timer=null)},n.initAbort=function(e){var t=e.controller,n=e.timer,r=e.timeout;return!n&&(e.timer=setTimeout((function(){return t.abort()}),r)),e},n.requestType=function(){switch(n.envDesc()){case"Window":return n.fetch;case"Node":return n.http}},n.getDataByType=function(e,t){switch(e){case"text":case"json":case"blob":case"formData":case"arrayBuffer":return t[e]();default:return t.json()}},n.formatBodyString=function(e){return{text:function(){return e},json:function(){var t;return null!==(t=g(e))&&void 0!==t?t:e},blob:function(){return g(e)},formData:function(){return g(e)},arrayBuffer:function(){return g(e)}}},n.origin=null!=t?t:"",n}return n(t,e),t}(function(){function e(){}return e.prototype.use=function(e,t){switch(e){case"request":this.requestSuccess=t;break;case"response":this.responseSuccess=t;break;case"error":this.error=t}return this},Object.defineProperty(e.prototype,"reqFn",{get:function(){return this.requestSuccess},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"resFn",{get:function(){return this.responseSuccess},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"errFn",{get:function(){return this.error},enumerable:!1,configurable:!0}),e}()),G=function(e){function t(t){var n=e.call(this,t)||this;return n.initDefaultParams=function(e,t){var i,u,a=t.method,c=void 0===a?"GET":a,s=t.query,l=void 0===s?{}:s,f=t.headers,p=void 0===f?{}:f,d=t.body,h=void 0===d?null:d,v=t.timeout,y=void 0===v?3e4:v,m=t.controller,g=void 0===m?new J:m,w=t.type,j=void 0===w?"json":w,O=o(t,["method","query","headers","body","timeout","controller","type"]),E=r({url:e,method:c,query:l,headers:p,body:"GET"===c?null:b(h),timeout:y,signal:null==g?void 0:g.signal,controller:g,type:j,timer:null},O),T=null!==(u=null===(i=n.reqFn)||void 0===i?void 0:i.call(n,E))&&void 0!==u?u:E;return T.url=q(n.fixOrigin(e),E.query),T},n.initFetchParams=function(e,t){return n.initAbort(n.initDefaultParams(e,t))},n.initHttpParams=function(e,t){var o=n.initAbort(n.initDefaultParams(e,t)),i=W(o.url,!0);return r(r({},o),i)},n}return n(t,e),t}(V),Q=function(e){function t(t){var n=e.call(this,t)||this;return n.fetch=function(e,t){var r=F(),i=r.promise,u=r.resolve,a=r.reject,c=n.initFetchParams(e,t),s=c.url,l=o(c,["url"]),f=l.signal;return i.finally((function(){return n.clearTimer(l)})),f.addEventListener("abort",(function(){return n.errorFn(a)})),fetch(s,l).then((function(e){return(null==e?void 0:e.status)>=200&&(null==e?void 0:e.status)<300?n.getDataByType(l.type,e):n.errorFn(a)})).then((function(e){var t,r;return u(null!==(r=null===(t=n.resFn)||void 0===t?void 0:t.call(n,e))&&void 0!==r?r:e)})).catch(n.errorFn(a)),i},n.http=function(e,t){var r=F(),o=r.promise,i=r.resolve,u=r.reject,a=n.initHttpParams(e,t),c=a.signal,s=a.url;o.finally((function(){return n.clearTimer(a)}));var l=(n.checkIsHttps(s)?N:B)(a,(function(e){if((null==e?void 0:e.statusCode)>=200&&(null==e?void 0:e.statusCode)<300){var t="";return e.setEncoding("utf8"),e.on("data",(function(e){return t+=e})),e.on("end",(function(){var e,r,o=n.getDataByType(a.type,n.formatBodyString(t));i(null!==(r=null===(e=n.resFn)||void 0===e?void 0:e.call(n,o))&&void 0!==r?r:o)}))}return n.errorFn(u)(null==e?void 0:e.statusMessage)}));return c.addEventListener("abort",(function(){return n.errorFn(u)(l.destroy(new Error("request timeout")))})),l.on("error",n.errorFn(u)),l.end(),o},n.GET=function(e,t,o,i){return n.request(e,r({query:t,method:"GET"},i))},n.POST=function(e,t,o,i){return n.request(e,r({query:t,method:"POST",body:o},i))},n.PUT=function(e,t,o,i){return n.request(e,r({query:t,method:"PUT",body:o},i))},n.DELETE=function(e,t,o,i){return n.request(e,r({query:t,method:"DELETE",body:o},i))},n.OPTIONS=function(e,t,o,i){return n.request(e,r({query:t,method:"OPTIONS",body:o},i))},n.HEAD=function(e,t,o,i){return n.request(e,r({query:t,method:"HEAD",body:o},i))},n.PATCH=function(e,t,o,i){return n.request(e,r({query:t,method:"PATCH",body:o},i))},n.request=n.requestType(),n}return n(t,e),t}(G),K={Request:Q},$=function(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e["on"+t]=n},z=function(e){(e=e||window.event).stopPropagation?e.stopPropagation():e.cancelBubble=!1},X=function(e){(e=e||window.event).preventDefault?e.preventDefault():e.returnValue=!1},Y=function(e,t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e["on"+t]=null},Z=function(e,t){var n=new Event(t);e.dispatchEvent(n)},ee={addHandler:$,stopBubble:z,stopDefault:X,removeHandler:Y,dispatchEvent:Z},te=function(e,t){try{localStorage.setItem(e,JSON.stringify(t))}catch(e){console.error(e)}},ne=function(e){try{var t=localStorage.getItem(e);return null==t?null:JSON.parse(t)}catch(e){return console.error(e),null}},re=function(e){try{e&&localStorage.removeItem(e),!e&&localStorage.clear()}catch(e){console.error(e)}},oe={setStorage:te,getStorage:ne,clearStorage:re},ie=function(e,t,n){void 0===t&&(t=!1),void 0===n&&(n=!0),t&&(process.stdout.clearLine(0),process.stdout.cursorTo(0)),process.stdout.write(e),n&&process.stdout.write("\n")},ue=function(e){return ie(e,!0,!1)},ae=["\\","|","/","—","—"],ce=function(e){var t;void 0===e&&(e={});var n=e.loopList,r=void 0===n?ae:n,o=e.isStop,i=void 0!==o&&o,u=e.timer,a=void 0===u?100:u,c=e.index,s=void 0===c?0:c,l=null!==(t=null==r?void 0:r.length)&&void 0!==t?t:0;if(!l)return e;if(i)return ue("\n");s>=l-1&&(s=0);var f=r[s++];return ue(f),setTimeout((function(){e.index=s,ce(e)}),a),e},se={logOneLine:ie,logLoop:ce},le=function(){function e(e){void 0===e&&(e={}),this.options=e,this.events={}}return e.prototype.on=function(e,t){return this.checkHandler(e,t),this.getHandler(e,[]).push(t),this},e.prototype.emit=function(e,t){return this.has(e)&&this.runHandler(e,t),this},e.prototype.un=function(e,t){return this.unHandler(e,t),this},e.prototype.once=function(e,t){var n=this;this.checkHandler(e,t);var r=function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];return n.un(e,r),t.apply(void 0,o)};return this.on(e,r),this},e.prototype.clear=function(){return this.events={},this},e.prototype.has=function(e){return!!this.getHandler(e)},e.prototype.getHandler=function(e,t){var n;return"object"==typeof t&&(this.events[e]=null!==(n=this.events[e])&&void 0!==n?n:t),this.events[e]},e.prototype.handlerLength=function(e){var t,n;return null!==(n=null===(t=this.getHandler(e))||void 0===t?void 0:t.length)&&void 0!==n?n:0},e.prototype.watch=function(e,t){var n=this;this.checkHandler(e,t);return this.on(e,(function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];n.emit(n.prefixStr(e),t.apply(void 0,r))})),this},e.prototype.invoke=function(e,t){var n=this;return new Promise((function(r){n.once(n.prefixStr(e),r),n.emit(e,t)}))},e.prototype.runHandler=function(e,t){for(var n=0,r=this.getHandler(e);n<r.length;n++){var o=r[n];o&&o(t)}},e.prototype.unHandler=function(e,t){var n=this.getHandler(e);!t&&(this.events[e]=[]),t&&this.checkHandler(e,t);for(var r=0;r<n.length;r++)n&&n[r]===t&&(n[r]=null)},e.prototype.prefixStr=function(e){return"@".concat(e)},e.prototype.checkHandler=function(e,t){var n=this.options,r=n.blackList,o=void 0===r?[]:r,i=n.maxLen,u=void 0===i?1/0:i,a=this.handlerLength(e);if(0===(null==e?void 0:e.length))throw new Error("type.length can not be 0");if(!t||!e)throw new ReferenceError("type or handler is not defined");if("function"!=typeof t||"string"!=typeof e)throw new TypeError("".concat(t," is not a function or ").concat(e," is not a string"));if(o.includes(e))throw new Error("".concat(e," is not allow"));if(u<=a)throw new Error("the number of ".concat(e," must be less than ").concat(u))},e.Instance=function(e){return e._instance||Object.defineProperty(e,"_instance",{value:new e}),e._instance},e}(),fe=le.Instance(le),pe=function(e){return e.prototype.messageCenter||(e.prototype.messageCenter=new le),e},de=function(){return de=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},de.apply(this,arguments)},he=function(e,t,n,r){var o,i=arguments.length,u=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)u=Reflect.decorate(e,t,n,r);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(u=(i<3?o(u):i>3?o(t,n,u):o(t,n))||u);return i>3&&u&&Object.defineProperty(t,n,u),u},ve=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},ye=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,a)}c((r=r.apply(e,t||[])).next())}))},me=function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},ge=function(){function e(e){var t=this;this.fix="@~&$",this.init=function(){t.messageCenter.on("push:handler",t.run),t.messageCenter.on("run:success:handler",t.run),t.messageCenter.on("run:success:handler",t.finish),t.messageCenter.on("run:error:handler",t.run),t.messageCenter.on("run:error:handler",t.finish)},this.defineProps=function(e,n){Object.defineProperty(t,n,{value:e})},this.push=function(e){var n;t.checkHandler(e);var r=(n=t.defer()).resolve,o=n.reject,i=n.promise,u=t.fixStr(e.name);return t.queues=t.queues.concat(e.children.map((function(e){return{defer:e,name:u}}))),t.queueTemp[u]=de(de({},e),{result:[]}),t.messageCenter.emit("push:handler",o),t.messageCenter.on(u,r),i},this.unshift=function(e){return t.queues.splice(0,e)},this.run=function(e){var n=e.reject;return ye(t,void 0,void 0,(function(){var e,t,r,o,i;return me(this,(function(u){switch(u.label){case 0:if("pending"===this.stateProxy())return[2,void 0];if(0===this.queues.length)return[2,this.stateProxy("idle")];this.stateProxy("pending"),e=this.unshift(null!==(i=null===(o=this.props)||void 0===o?void 0:o.maxLen)&&void 0!==i?i:10),u.label=1;case 1:return u.trys.push([1,3,,4]),[4,Promise.all(e.map((function(e,t){return e.defer().catch((function(e){return e}))})))];case 2:return t=u.sent(),[2,this.handlerSuccess({res:t,queues:e})];case 3:return r=u.sent(),[2,this.handlerError({reject:n,error:r,queues:e})];case 4:return[2]}}))}))},this.clear=function(){t.queues=[],t.queueTemp={},t.props=null,t.stateProxy("idle"),t.messageCenter.clear()},this.finish=function(e){var n=e.res,r=void 0===n?[]:n,o=e.queues,i=e.error,u=void 0===i?"err":i,a=t.queueTemp;o.forEach((function(e,n){var o,i,c,s=a[e.name];null==s||s.result.push(null!==(o=r[n])&&void 0!==o?o:u),(null===(i=null==s?void 0:s.result)||void 0===i?void 0:i.length)===(null===(c=null==s?void 0:s.children)||void 0===c?void 0:c.length)&&(t.messageCenter.emit(e.name,null==s?void 0:s.result),a[e.name]=null)}))},this.handlerSuccess=function(e){return t.stateProxy("fulfilled"),t.messageCenter.emit("run:success:handler",e)},this.handlerError=function(e){var n=e.reject,r=e.error;return t.stateProxy("rejected"),n&&"function"==typeof n&&n(r),t.messageCenter.emit("run:error:handler",e)},this.stateProxy=function(e){return e&&(t.state=e),t.state},this.defer=function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),resolve:e,reject:t}},this.clear(),e&&this.defineProps(e,"props"),this.init()}return e.prototype.checkHandler=function(e){var t,n;if(!e)throw new ReferenceError("queue is not defined");if(!(e.children instanceof Array)||"object"!=typeof e)throw new TypeError("queue should be an object and queue.children should be an array");if(0===(null===(t=e.children)||void 0===t?void 0:t.length))throw new Error("queue.children.length can not be 0");if(null===(n=e.children)||void 0===n?void 0:n.find((function(e){return function(e){return!e||"function"!=typeof e}(e)})))throw new Error("queueList should have defer")},e.prototype.fixStr=function(e){return"".concat(this.fix).concat(e)},e=he([pe,ve("design:paramtypes",[Object])],e)}(),be=r(r(r(r(r(r(r(r(r(r(r({},j),P),D),R),M),U),K),ee),oe),se),{eventMessageCenter:le,taskQueueLib:ge});return e.MessageCenter=le,e.Request=Q,e.TaskQueue=ge,e.addHandler=$,e.arrayDemote=H,e.arrayRandom=x,e.arrayUniq=k,e.catchAwait=I,e.classDecorator=m,e.clearStorage=re,e.cloneDeep=p,e.createElement=_,e.createObject=h,e.createObjectVariable=d,e.debounce=A,e.decoratorMessageCenter=pe,e.decoratorTaskQueue=function(e){return function(t){t.prototype.taskQueue||(t.prototype.taskQueue=new ge(e))}},e.default=be,e.defer=F,e.dispatchEvent=Z,e.enumInversion=l,e.getInstance=y,e.getStorage=ne,e.getType=T,e.getTypeByList=S,e.getValue=a,e.inherit=v,e.isNotObject=f,e.isWindow=w,e.jsonToString=b,e.logLoop=ce,e.logOneLine=ie,e.messageCenter=fe,e.mixIn=s,e.randomNum=O,e.removeHandler=Y,e.setStorage=te,e.setValue=c,e.stopBubble=z,e.stopDefault=X,e.stringToJson=g,e.throttle=L,e.urlJoin=q,e.urlSplit=E,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
|
package/dist/bundle/object.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare const getInstance: IGetInstance;
|
|
|
12
12
|
export declare const classDecorator: IClassDecorator;
|
|
13
13
|
export declare const stringToJson: IStringToJson;
|
|
14
14
|
export declare const jsonToString: IJsonToString;
|
|
15
|
+
export declare const isWindow: (win: any) => boolean;
|
|
15
16
|
declare const _default: {
|
|
16
17
|
getValue: IGetValue;
|
|
17
18
|
setValue: ISetValue;
|
|
@@ -26,5 +27,6 @@ declare const _default: {
|
|
|
26
27
|
classDecorator: IClassDecorator;
|
|
27
28
|
stringToJson: IStringToJson;
|
|
28
29
|
jsonToString: IJsonToString;
|
|
30
|
+
isWindow: (win: any) => boolean;
|
|
29
31
|
};
|
|
30
32
|
export default _default;
|
package/dist/bundle/request.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IRequest, IRequestBase, IRequestInit, IInterceptors, IUrl, IObject, IRequestBody, IRequestOptions, IRequestBaseFn, IEnv } from "./index";
|
|
2
|
-
import CustomAbortController from "abort-controller";
|
|
3
2
|
declare class Interceptors implements IInterceptors {
|
|
4
3
|
private requestSuccess;
|
|
5
4
|
private responseSuccess;
|
|
@@ -36,7 +35,7 @@ declare abstract class RequestInit extends RequestBase implements IRequestInit {
|
|
|
36
35
|
headers?: {};
|
|
37
36
|
body?: any;
|
|
38
37
|
timeout?: number;
|
|
39
|
-
controller?:
|
|
38
|
+
controller?: any;
|
|
40
39
|
type?: string;
|
|
41
40
|
}) => IRequestOptions;
|
|
42
41
|
initFetchParams: (url: IUrl, opts: IRequestOptions) => any;
|
package/dist/bundle/types.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type IStringToJson = (target: string) => IObject<any> | null;
|
|
|
31
31
|
export type IJsonToString = (target: IObject<any>) => string;
|
|
32
32
|
export type IThrottle = (fn: Function, time: number) => (...args: any[]) => void;
|
|
33
33
|
export type IDebounce = (fn: Function, time: number) => (...args: any[]) => void;
|
|
34
|
-
export type IDefer = () => IPromise;
|
|
34
|
+
export type IDefer = (timer?: number) => IPromise;
|
|
35
35
|
export type ICatchAwait<T extends Promise<any>> = (defer: T) => T;
|
|
36
36
|
export type IArrayRandom<T extends any[]> = (arr: T) => T;
|
|
37
37
|
export type IArrayUniq<T extends any[]> = (arr: T) => T;
|
package/dist/cjs/index.d.ts
CHANGED