ddan-js 1.1.4 → 1.1.5
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/bin/ddan-js.esm.js +1 -1
- package/bin/ddan-js.js +1 -1
- package/bin/lib/class/event.js +23 -43
- package/bin/lib/class/task.js +9 -10
- package/bin/lib/common/_Symbol.js +2 -2
- package/bin/lib/common/_object.js +10 -10
- package/bin/lib/common/_root.js +1 -1
- package/bin/lib/index.js +7 -7
- package/bin/lib/modules/gbk.js +6 -6
- package/bin/lib/modules/hook/debounce.js +7 -13
- package/bin/lib/modules/hook/index.js +6 -9
- package/bin/lib/modules/hook/throttle.js +4 -6
- package/bin/lib/modules/list.js +54 -9
- package/bin/lib/modules/math/index.js +1 -1
- package/bin/lib/modules/time.js +10 -12
- package/bin/lib/util/includes.js +3 -3
- package/bin/lib/util/index.js +4 -15
- package/bin/lib/util/is.js +21 -21
- package/bin/lib/util/to.js +12 -12
- package/bin/types/index.d.ts +3 -1
- package/bin/types/modules/list.d.ts +12 -2
- package/package.json +1 -1
package/bin/ddan-js.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t={gbkLength:function(t){
|
|
1
|
+
var t={gbkLength:function(t){let e=0;if(!t)return 0;for(let n=0;n<t.length;n++)t.charCodeAt(n)>127||94===t.charCodeAt(n)?e+=2:e++;return e},gbkCut:function(t,e){if(!t||e<=0)return"";let n=0,r=0;for(let i=0;i<t.length&&(t.charCodeAt(i)>127||94===t.charCodeAt(i)?n+=2:n++,!(n>e));i++)r=i;return t.substr(0,r+1)}},e="object"==typeof global&&global&&global.Object===Object&&global,n="object"==typeof self&&self&&self.Object===Object&&self,r=e||n||Function("return this")();const i=(t,e="yyyy-MM-dd hh:mm:ss")=>{const n="string"==typeof t||"number"==typeof t?new Date(t):t,r={};return r.yyyy=n.getFullYear(),r.yy=`${r.yyyy}`.substr(2),r.M=n.getMonth()+1,r.MM=(r.M<10?"0":"")+r.M,r.d=n.getDate(),r.dd=(r.d<10?"0":"")+r.d,r.h=n.getHours(),r.hh=(r.h<10?"0":"")+r.h,r.m=n.getMinutes(),r.mm=(r.m<10?"0":"")+r.m,r.s=n.getSeconds(),r.ss=(r.s<10?"0":"")+r.s,r.S=n.getMilliseconds(),r.SS=(r.S<10?"0":"")+r.S,r.SSS=r.S.toString().padStart(3,0),e.replace(/\byyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g,(t=>r[t]))};var o={now:function(){return r.Date.now()},isToday:t=>(new Date).toDateString()===new Date(t).toDateString(),format:i,parseTime:function({year:t=0,month:e=0,date:n=0,hour:r=0,minute:o=0,second:u=0}){const s=`${t||"yyyy"}/${e||"MM"}/${n||"dd"} ${r}:${o}:${u}`;return new Date(i(Date.now(),s)).getTime()}};const u=r.Symbol,{toString:s,hasOwnProperty:c,propertyIsEnumerable:a}=Object.prototype,f=u?u.toStringTag:void 0;function l(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":f&&f in Object(t)?function(t){const e=c.call(t,f),n=t[f];let r=!1;try{t[f]=void 0,r=!0}catch(t){}const i=s.call(t);return r&&(e?t[f]=n:delete t[f]),i}(t):s.call(t)}var h={getTag:l,getType:function(t){return(l(t).match(/\w+/g)||["object","Undefined"])[1]||""},toString:s,hasOwnProperty:c,propertyIsEnumerable:a},g="[object Function]",y="[object GeneratorFunction]",m="[object AsyncFunction]",b=9007199254740991;const p=/^(?:0|[1-9]\d*)$/;function d(t){const e=typeof t;return null!=t&&("object"==e||"function"==e)}function v(t){return null!=t&&"object"==typeof t}const j=Array.isArray;function S(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=b}(t.length)&&!w(t)}function O(t){return v(t)&&S(t)}function w(t){var e=d(t)?h.getTag(t):"";return e===g||e===y||e===m}var A={is:function(t,e){return h.getTag(t)===`[object ${e}]`},isNumber:function(t){return"[object Number]"===h.getTag(t)},isString:function(t){return"string"==typeof t||!j(t)&&v(t)&&"[object String]"==h.getTag(t)},isChinese:function(t){return!!t&&!!/^[\u4E00-\u9FA5]+$/.test(t)},isObject:d,isObjectLike:v,isSymbol:function(t){return"symbol"==typeof t||v(t)&&"[object Symbol]"===h.getTag(t)},isFunction:w,isArray:j,isArrayLikeObject:O,isIndex:function(t,e){return!!(e=null==e?b:e)&&("number"==typeof t||p.test(t))&&t>-1&&t%1==0&&t<e},isArrayLike:S,isPrototype:function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Object.prototype)},isArguments:function(t){return O(t)&&h.hasOwnProperty.call(t,"callee")&&(!h.propertyIsEnumerable.call(t,"callee")||"[object Arguments]"==h.toString.call(t))},isPromise:function(t){return"[object Promise]"===(d(t)?h.getTag(t):"")}};const M=NaN,T=/^\s+|\s+$/g,$=/^[-+]0x[0-9a-f]+$/i,D=/^0b[01]+$/i,P=/^0o[0-7]+$/i,k=parseInt,x=1/0,E=17976931348623157e292;function F(t){if("number"==typeof t)return t;if(A.isSymbol(t))return M;if(A.isObject(t)){const e="function"==typeof t.valueOf?t.valueOf():t;t=A.isObject(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(T,"");const e=D.test(t);return e||P.test(t)?k(t.slice(2),e?2:8):$.test(t)?M:+t}function _(t){return t?(t=F(t))===x||t===-x?(t<0?-1:1)*E:t==t?t:0:0===t?t:0}var I={toNumber:F,toFinite:_,toInteger:function(t){var e=_(t),n=e%1;return e==e?n?e-n:e:0}};const N="Expected a function",C=Math.max,L=Math.min;function W(t,e=0,n={}){var r,i,o,u,s,c,a=0,f=!1,l=!1,h=!0;if("function"!=typeof t)throw new TypeError(N);function g(e){var n=r,o=i;return r=i=void 0,a=e,u=t.apply(o,n)}function y(t){var n=t-c;return void 0===c||n>=e||n<0||l&&t-a>=o}function m(){var t=Date.now();if(y(t))return b(t);s=setTimeout(m,function(t){var n=e-(t-c);return l?L(n,o-(t-a)):n}(t))}function b(t){return s=void 0,h&&r?g(t):(r=i=void 0,u)}function p(...t){var n=Date.now(),o=y(n);if(r=arguments,i=this,c=n,o){if(void 0===s)return function(t){return a=t,s=setTimeout(m,e),f?g(t):u}(c);if(l)return s=setTimeout(m,e),g(c)}return void 0===s&&(s=setTimeout(m,e)),u}return e=I.toNumber(e)||0,A.isObject(n)&&(f=!!n.leading,o=(l="maxWait"in n)?C(I.toNumber(n.maxWait)||0,e):o,h="trailing"in n?!!n.trailing:h),p.cancel=function(){void 0!==s&&clearTimeout(s),a=0,r=c=i=s=void 0},p.flush=function(){return void 0===s?u:b(Date.now())},p}class U{constructor(t){this.source=t}run(){let t;try{let e;return e=A.isFunction(this.source)?this.source():this.source,t=A.isPromise(e)?e:Promise.resolve(e),t.then((t=>[null,t])).catch((t=>[t,void 0]))}catch(t){return Promise.resolve([t,void 0])}}}var B={sleep:(t=1e3)=>new Promise((e=>{setTimeout(e,t)})),run:t=>new U(t).run(),debounce:W,throttle:function(t,e=0,n={}){var r=!1,i=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return A.isObject(n)&&(r=n.leading?!!n.leading:r,i=n.trailing?!!n.trailing:i),W(t,e,{leading:r,maxWait:e,trailing:i})}};var G={random:function(t){return Math.floor(Math.random()*t)},randomRange:function(t,e){return Math.floor(Math.random()*(e-t+1)+t)},lerp:function(t,e,n){return t*(1-n)+e*n}};function H(t){return t!=t}function R(t,e){return function(t,e){for(var n=-1,r=t?t.length:0,i=Array(r);++n<r;)i[n]=e(t[n],n,t);return i}(e,(function(e){return t[e]}))}var Y,q,z=(Y=Object.keys,q=Object,function(t){return Y(q(t))}),J=Math.max;function K(t,e){var n=A.isArray(t)||A.isArguments(t)?function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}(t.length,String):[],r=n.length,i=!!r;for(var o in t)!e&&!h.hasOwnProperty.call(t,o)||i&&("length"==o||A.isIndex(o,r))||n.push(o);return n}var Q=Object.assign(Object.assign(Object.assign({},A),h),{includes:function(t,e,n,r){var i;t=A.isArrayLike(t)?t:(i=t)?R(i,function(t){return A.isArrayLike(t)?K(t):function(t){if(!A.isPrototype(t))return z(t);var e=[];for(var n in Object(t))h.hasOwnProperty.call(t,n)&&"constructor"!=n&&e.push(n);return e}(t)}(i)):[],n=n&&!r?I.toInteger(n):0;var o=t.length;return n<0&&(n=J(o+n,0)),A.isString(t)?n<=o&&t.indexOf(e,n)>-1:!!o&&function(t,e,n){if(e!=e)return function(t,e,n,r){for(var i=t.length,o=n+(r?1:-1);r?o--:++o<i;)if(e(t[o],o,t))return o;return-1}(t,H,n);for(var r=n-1,i=t.length;++r<i;)if(t[r]===e)return r;return-1}(t,e,n)>-1}});class V{constructor(){this._map=new Map}clear(){return this._map.clear(),this}on(t,e){if(!e)return this;let n=this._map.get(t);return n||(n=new Set,this._map.set(t,n)),n.add(e),this}emit(t,...e){const n=this._map.get(t);if(!n)return this;return[...n].forEach((t=>t(...e))),this}off(t="",e){if(!t)return this._map.clear(),this;if(!e)return this._map.delete(t.toString()),this;const n=this._map.get(t);return n?(n.delete(e),this):this}once(t,e){const n=(...r)=>{e(...r),this.off(t,n)};return this.on(t,n),this}has(t){return this._map.has(t)}}var X={groupBy:(t,e)=>t.reduce(((t,n)=>((t[n[e]]=t[n[e]]||[]).push(n),t)),{}),stepAction:function(t,e,n=100){if(!A.isFunction(e))return;if(!A.isArray(t)||t.length<=0)return;let r=0;for(;t.length>r;){let i=n+r,o=t.slice(r,i);e&&e(o),r=i}},skip:(t,e)=>{if(!A.isArray(t)||t.length<=0)return[];const n=e;return t.slice(n)},take:(t,e,n=0)=>{if(!A.isArray(t)||t.length<=0)return[];const r=n||0;if(r>=t.length)return[];const i=e+r;return t.slice(r,t.length>i?t.length:i)||[]},distinct:t=>!A.isArray(t)||t.length<=0?[]:[...new Set(t)]},Z={gbk:t,time:o,hook:B,math:G,util:Q,list:X,DEvent:V};export{V as DEvent,Z as default,t as gbk,B as hook,X as list,G as math,o as time,Q as util};
|
package/bin/ddan-js.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,
|
|
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).ddan={})}(this,(function(t){"use strict";var e={gbkLength:function(t){let e=0;if(!t)return 0;for(let n=0;n<t.length;n++)t.charCodeAt(n)>127||94===t.charCodeAt(n)?e+=2:e++;return e},gbkCut:function(t,e){if(!t||e<=0)return"";let n=0,r=0;for(let i=0;i<t.length&&(t.charCodeAt(i)>127||94===t.charCodeAt(i)?n+=2:n++,!(n>e));i++)r=i;return t.substr(0,r+1)}},n="object"==typeof global&&global&&global.Object===Object&&global,r="object"==typeof self&&self&&self.Object===Object&&self,i=n||r||Function("return this")();const o=(t,e="yyyy-MM-dd hh:mm:ss")=>{const n="string"==typeof t||"number"==typeof t?new Date(t):t,r={};return r.yyyy=n.getFullYear(),r.yy=`${r.yyyy}`.substr(2),r.M=n.getMonth()+1,r.MM=(r.M<10?"0":"")+r.M,r.d=n.getDate(),r.dd=(r.d<10?"0":"")+r.d,r.h=n.getHours(),r.hh=(r.h<10?"0":"")+r.h,r.m=n.getMinutes(),r.mm=(r.m<10?"0":"")+r.m,r.s=n.getSeconds(),r.ss=(r.s<10?"0":"")+r.s,r.S=n.getMilliseconds(),r.SS=(r.S<10?"0":"")+r.S,r.SSS=r.S.toString().padStart(3,0),e.replace(/\byyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g,(t=>r[t]))};var u={now:function(){return i.Date.now()},isToday:t=>(new Date).toDateString()===new Date(t).toDateString(),format:o,parseTime:function({year:t=0,month:e=0,date:n=0,hour:r=0,minute:i=0,second:u=0}){const s=`${t||"yyyy"}/${e||"MM"}/${n||"dd"} ${r}:${i}:${u}`;return new Date(o(Date.now(),s)).getTime()}};const s=i.Symbol,{toString:c,hasOwnProperty:a,propertyIsEnumerable:f}=Object.prototype,l=s?s.toStringTag:void 0;function h(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":l&&l in Object(t)?function(t){const e=a.call(t,l),n=t[l];let r=!1;try{t[l]=void 0,r=!0}catch(t){}const i=c.call(t);return r&&(e?t[l]=n:delete t[l]),i}(t):c.call(t)}var g={getTag:h,getType:function(t){return(h(t).match(/\w+/g)||["object","Undefined"])[1]||""},toString:c,hasOwnProperty:a,propertyIsEnumerable:f},y="[object Function]",d="[object GeneratorFunction]",m="[object AsyncFunction]",p=9007199254740991;const b=/^(?:0|[1-9]\d*)$/;function v(t){const e=typeof t;return null!=t&&("object"==e||"function"==e)}function j(t){return null!=t&&"object"==typeof t}const S=Array.isArray;function O(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=p}(t.length)&&!A(t)}function w(t){return j(t)&&O(t)}function A(t){var e=v(t)?g.getTag(t):"";return e===y||e===d||e===m}var M={is:function(t,e){return g.getTag(t)===`[object ${e}]`},isNumber:function(t){return"[object Number]"===g.getTag(t)},isString:function(t){return"string"==typeof t||!S(t)&&j(t)&&"[object String]"==g.getTag(t)},isChinese:function(t){return!!t&&!!/^[\u4E00-\u9FA5]+$/.test(t)},isObject:v,isObjectLike:j,isSymbol:function(t){return"symbol"==typeof t||j(t)&&"[object Symbol]"===g.getTag(t)},isFunction:A,isArray:S,isArrayLikeObject:w,isIndex:function(t,e){return!!(e=null==e?p:e)&&("number"==typeof t||b.test(t))&&t>-1&&t%1==0&&t<e},isArrayLike:O,isPrototype:function(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Object.prototype)},isArguments:function(t){return w(t)&&g.hasOwnProperty.call(t,"callee")&&(!g.propertyIsEnumerable.call(t,"callee")||"[object Arguments]"==g.toString.call(t))},isPromise:function(t){return"[object Promise]"===(v(t)?g.getTag(t):"")}};const T=NaN,k=/^\s+|\s+$/g,x=/^[-+]0x[0-9a-f]+$/i,D=/^0b[01]+$/i,P=/^0o[0-7]+$/i,$=parseInt,E=1/0,_=17976931348623157e292;function F(t){if("number"==typeof t)return t;if(M.isSymbol(t))return T;if(M.isObject(t)){const e="function"==typeof t.valueOf?t.valueOf():t;t=M.isObject(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(k,"");const e=D.test(t);return e||P.test(t)?$(t.slice(2),e?2:8):x.test(t)?T:+t}function I(t){return t?(t=F(t))===E||t===-E?(t<0?-1:1)*_:t==t?t:0:0===t?t:0}var N={toNumber:F,toFinite:I,toInteger:function(t){var e=I(t),n=e%1;return e==e?n?e-n:e:0}};const C="Expected a function",L=Math.max,W=Math.min;function U(t,e=0,n={}){var r,i,o,u,s,c,a=0,f=!1,l=!1,h=!0;if("function"!=typeof t)throw new TypeError(C);function g(e){var n=r,o=i;return r=i=void 0,a=e,u=t.apply(o,n)}function y(t){var n=t-c;return void 0===c||n>=e||n<0||l&&t-a>=o}function d(){var t=Date.now();if(y(t))return m(t);s=setTimeout(d,function(t){var n=e-(t-c);return l?W(n,o-(t-a)):n}(t))}function m(t){return s=void 0,h&&r?g(t):(r=i=void 0,u)}function p(...t){var n=Date.now(),o=y(n);if(r=arguments,i=this,c=n,o){if(void 0===s)return function(t){return a=t,s=setTimeout(d,e),f?g(t):u}(c);if(l)return s=setTimeout(d,e),g(c)}return void 0===s&&(s=setTimeout(d,e)),u}return e=N.toNumber(e)||0,M.isObject(n)&&(f=!!n.leading,o=(l="maxWait"in n)?L(N.toNumber(n.maxWait)||0,e):o,h="trailing"in n?!!n.trailing:h),p.cancel=function(){void 0!==s&&clearTimeout(s),a=0,r=c=i=s=void 0},p.flush=function(){return void 0===s?u:m(Date.now())},p}class B{constructor(t){this.source=t}run(){let t;try{let e;return e=M.isFunction(this.source)?this.source():this.source,t=M.isPromise(e)?e:Promise.resolve(e),t.then((t=>[null,t])).catch((t=>[t,void 0]))}catch(t){return Promise.resolve([t,void 0])}}}var G={sleep:(t=1e3)=>new Promise((e=>{setTimeout(e,t)})),run:t=>new B(t).run(),debounce:U,throttle:function(t,e=0,n={}){var r=!1,i=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return M.isObject(n)&&(r=n.leading?!!n.leading:r,i=n.trailing?!!n.trailing:i),U(t,e,{leading:r,maxWait:e,trailing:i})}};var H={random:function(t){return Math.floor(Math.random()*t)},randomRange:function(t,e){return Math.floor(Math.random()*(e-t+1)+t)},lerp:function(t,e,n){return t*(1-n)+e*n}};function R(t){return t!=t}function Y(t,e){return function(t,e){for(var n=-1,r=t?t.length:0,i=Array(r);++n<r;)i[n]=e(t[n],n,t);return i}(e,(function(e){return t[e]}))}var q,z,J=(q=Object.keys,z=Object,function(t){return q(z(t))}),K=Math.max;function Q(t,e){var n=M.isArray(t)||M.isArguments(t)?function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}(t.length,String):[],r=n.length,i=!!r;for(var o in t)!e&&!g.hasOwnProperty.call(t,o)||i&&("length"==o||M.isIndex(o,r))||n.push(o);return n}var V=Object.assign(Object.assign(Object.assign({},M),g),{includes:function(t,e,n,r){var i;t=M.isArrayLike(t)?t:(i=t)?Y(i,function(t){return M.isArrayLike(t)?Q(t):function(t){if(!M.isPrototype(t))return J(t);var e=[];for(var n in Object(t))g.hasOwnProperty.call(t,n)&&"constructor"!=n&&e.push(n);return e}(t)}(i)):[],n=n&&!r?N.toInteger(n):0;var o=t.length;return n<0&&(n=K(o+n,0)),M.isString(t)?n<=o&&t.indexOf(e,n)>-1:!!o&&function(t,e,n){if(e!=e)return function(t,e,n,r){for(var i=t.length,o=n+(r?1:-1);r?o--:++o<i;)if(e(t[o],o,t))return o;return-1}(t,R,n);for(var r=n-1,i=t.length;++r<i;)if(t[r]===e)return r;return-1}(t,e,n)>-1}});class X{constructor(){this._map=new Map}clear(){return this._map.clear(),this}on(t,e){if(!e)return this;let n=this._map.get(t);return n||(n=new Set,this._map.set(t,n)),n.add(e),this}emit(t,...e){const n=this._map.get(t);if(!n)return this;return[...n].forEach((t=>t(...e))),this}off(t="",e){if(!t)return this._map.clear(),this;if(!e)return this._map.delete(t.toString()),this;const n=this._map.get(t);return n?(n.delete(e),this):this}once(t,e){const n=(...r)=>{e(...r),this.off(t,n)};return this.on(t,n),this}has(t){return this._map.has(t)}}var Z={groupBy:(t,e)=>t.reduce(((t,n)=>((t[n[e]]=t[n[e]]||[]).push(n),t)),{}),stepAction:function(t,e,n=100){if(!M.isFunction(e))return;if(!M.isArray(t)||t.length<=0)return;let r=0;for(;t.length>r;){let i=n+r,o=t.slice(r,i);e&&e(o),r=i}},skip:(t,e)=>{if(!M.isArray(t)||t.length<=0)return[];const n=e;return t.slice(n)},take:(t,e,n=0)=>{if(!M.isArray(t)||t.length<=0)return[];const r=n||0;if(r>=t.length)return[];const i=e+r;return t.slice(r,t.length>i?t.length:i)||[]},distinct:t=>!M.isArray(t)||t.length<=0?[]:[...new Set(t)]},tt={gbk:e,time:u,hook:G,math:H,util:V,list:Z,DEvent:X};t.DEvent=X,t.default=tt,t.gbk=e,t.hook=G,t.list=Z,t.math=H,t.time=u,t.util=V,Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/bin/lib/class/event.js
CHANGED
|
@@ -1,47 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
class DEvent {
|
|
4
|
+
constructor() {
|
|
14
5
|
this._map = new Map();
|
|
15
6
|
}
|
|
16
|
-
|
|
7
|
+
clear() {
|
|
17
8
|
this._map.clear();
|
|
18
9
|
return this;
|
|
19
|
-
}
|
|
20
|
-
|
|
10
|
+
}
|
|
11
|
+
on(name, handler) {
|
|
21
12
|
if (!handler)
|
|
22
13
|
return this;
|
|
23
|
-
|
|
14
|
+
let handlers = this._map.get(name);
|
|
24
15
|
if (!handlers) {
|
|
25
16
|
handlers = new Set();
|
|
26
17
|
this._map.set(name, handlers);
|
|
27
18
|
}
|
|
28
19
|
handlers.add(handler);
|
|
29
20
|
return this;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
34
|
-
args[_i - 1] = arguments[_i];
|
|
35
|
-
}
|
|
36
|
-
var set = this._map.get(name);
|
|
21
|
+
}
|
|
22
|
+
emit(name, ...args) {
|
|
23
|
+
const set = this._map.get(name);
|
|
37
24
|
if (!set)
|
|
38
25
|
return this;
|
|
39
|
-
|
|
40
|
-
copied.forEach(
|
|
26
|
+
const copied = [...set];
|
|
27
|
+
copied.forEach((fn) => fn(...args));
|
|
41
28
|
return this;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (name === void 0) { name = ""; }
|
|
29
|
+
}
|
|
30
|
+
off(name = "", handler) {
|
|
45
31
|
// 什么都不传,则清除所有事件
|
|
46
32
|
if (!name) {
|
|
47
33
|
this._map.clear();
|
|
@@ -51,29 +37,23 @@ var DEvent = /** @class */ (function () {
|
|
|
51
37
|
this._map.delete(name.toString());
|
|
52
38
|
return this;
|
|
53
39
|
}
|
|
54
|
-
|
|
40
|
+
const handlers = this._map.get(name);
|
|
55
41
|
if (!handlers) {
|
|
56
42
|
return this;
|
|
57
43
|
}
|
|
58
44
|
handlers.delete(handler);
|
|
59
45
|
return this;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
66
|
-
args[_i] = arguments[_i];
|
|
67
|
-
}
|
|
68
|
-
handler.apply(void 0, args);
|
|
69
|
-
_this.off(name, warpper);
|
|
46
|
+
}
|
|
47
|
+
once(name, handler) {
|
|
48
|
+
const warpper = (...args) => {
|
|
49
|
+
handler(...args);
|
|
50
|
+
this.off(name, warpper);
|
|
70
51
|
};
|
|
71
52
|
this.on(name, warpper);
|
|
72
53
|
return this;
|
|
73
|
-
}
|
|
74
|
-
|
|
54
|
+
}
|
|
55
|
+
has(name) {
|
|
75
56
|
return this._map.has(name);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
}());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
79
59
|
exports.default = DEvent;
|
package/bin/lib/class/task.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const is_1 = require("../util/is");
|
|
4
|
+
class DTask {
|
|
5
|
+
constructor(source) {
|
|
6
6
|
this.source = source;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
run() {
|
|
9
|
+
let promise;
|
|
10
10
|
try {
|
|
11
|
-
|
|
11
|
+
let temp;
|
|
12
12
|
if (is_1.default.isFunction(this.source)) {
|
|
13
13
|
temp = this.source();
|
|
14
14
|
}
|
|
@@ -16,12 +16,11 @@ var DTask = /** @class */ (function () {
|
|
|
16
16
|
temp = this.source;
|
|
17
17
|
}
|
|
18
18
|
promise = is_1.default.isPromise(temp) ? temp : Promise.resolve(temp);
|
|
19
|
-
return promise.then(
|
|
19
|
+
return promise.then(data => [null, data]).catch(err => [err, undefined]);
|
|
20
20
|
}
|
|
21
21
|
catch (err) {
|
|
22
22
|
return Promise.resolve([err, undefined]);
|
|
23
23
|
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
}());
|
|
24
|
+
}
|
|
25
|
+
}
|
|
27
26
|
exports.default = DTask;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const _Symbol_1 = require("./_Symbol");
|
|
4
|
+
const { toString, hasOwnProperty, propertyIsEnumerable } = Object.prototype;
|
|
5
5
|
/** Built-in value references. */
|
|
6
|
-
|
|
6
|
+
const symToStringTag = _Symbol_1.default ? _Symbol_1.default.toStringTag : undefined;
|
|
7
7
|
function getRawTag(value) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const isOwn = hasOwnProperty.call(value, symToStringTag);
|
|
9
|
+
const tag = value[symToStringTag];
|
|
10
|
+
let unmasked = false;
|
|
11
11
|
try {
|
|
12
12
|
value[symToStringTag] = undefined;
|
|
13
13
|
unmasked = true;
|
|
14
14
|
}
|
|
15
15
|
catch (e) { }
|
|
16
|
-
|
|
16
|
+
const result = toString.call(value);
|
|
17
17
|
if (unmasked) {
|
|
18
18
|
if (isOwn) {
|
|
19
19
|
value[symToStringTag] = tag;
|
|
@@ -33,8 +33,8 @@ function getTag(value) {
|
|
|
33
33
|
: toString.call(value);
|
|
34
34
|
}
|
|
35
35
|
function getType(value) {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
let str = getTag(value);
|
|
37
|
+
const mat = str.match(/\w+/g) || ["object", "Undefined"];
|
|
38
38
|
return mat[1] || "";
|
|
39
39
|
}
|
|
40
|
-
exports.default = { getTag
|
|
40
|
+
exports.default = { getTag, getType, toString, hasOwnProperty, propertyIsEnumerable };
|
package/bin/lib/common/_root.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const _freeGlobal_1 = require("./_freeGlobal");
|
|
4
4
|
/** Detect free variable `self`. */
|
|
5
5
|
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
|
6
6
|
/** Used as a reference to the global object. */
|
package/bin/lib/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEvent = exports.list = exports.util = exports.math = exports.hook = exports.time = exports.gbk = void 0;
|
|
4
|
-
|
|
4
|
+
const gbk_1 = require("./modules/gbk");
|
|
5
5
|
exports.gbk = gbk_1.default;
|
|
6
|
-
|
|
6
|
+
const time_1 = require("./modules/time");
|
|
7
7
|
exports.time = time_1.default;
|
|
8
|
-
|
|
8
|
+
const hook_1 = require("./modules/hook");
|
|
9
9
|
exports.hook = hook_1.default;
|
|
10
|
-
|
|
10
|
+
const math_1 = require("./modules/math");
|
|
11
11
|
exports.math = math_1.default;
|
|
12
|
-
|
|
12
|
+
const util_1 = require("./util");
|
|
13
13
|
exports.util = util_1.default;
|
|
14
|
-
|
|
14
|
+
const event_1 = require("./class/event");
|
|
15
15
|
exports.DEvent = event_1.default;
|
|
16
|
-
|
|
16
|
+
const list_1 = require("./modules/list");
|
|
17
17
|
exports.list = list_1.default;
|
|
18
18
|
exports.default = { gbk: gbk_1.default, time: time_1.default, hook: hook_1.default, math: math_1.default, util: util_1.default, list: list_1.default, DEvent: event_1.default };
|
package/bin/lib/modules/gbk.js
CHANGED
|
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
* @returns
|
|
7
7
|
*/
|
|
8
8
|
function gbkLength(str) {
|
|
9
|
-
|
|
9
|
+
let len = 0;
|
|
10
10
|
if (!str)
|
|
11
11
|
return 0;
|
|
12
|
-
for (
|
|
12
|
+
for (let i = 0; i < str.length; i++) {
|
|
13
13
|
if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
|
|
14
14
|
len += 2;
|
|
15
15
|
}
|
|
@@ -27,9 +27,9 @@ function gbkLength(str) {
|
|
|
27
27
|
function gbkCut(source, len) {
|
|
28
28
|
if (!source || len <= 0)
|
|
29
29
|
return "";
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
for (
|
|
30
|
+
let n = 0;
|
|
31
|
+
let idx = 0;
|
|
32
|
+
for (let i = 0; i < source.length; i++) {
|
|
33
33
|
if (source.charCodeAt(i) > 127 || source.charCodeAt(i) === 94) {
|
|
34
34
|
n += 2;
|
|
35
35
|
}
|
|
@@ -43,4 +43,4 @@ function gbkCut(source, len) {
|
|
|
43
43
|
}
|
|
44
44
|
return source.substr(0, idx + 1);
|
|
45
45
|
}
|
|
46
|
-
exports.default = { gbkLength
|
|
46
|
+
exports.default = { gbkLength, gbkCut };
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function debounce(func, wait, options) {
|
|
9
|
-
if (wait === void 0) { wait = 0; }
|
|
10
|
-
if (options === void 0) { options = {}; }
|
|
3
|
+
const to_1 = require("../../util/to");
|
|
4
|
+
const is_1 = require("../../util/is");
|
|
5
|
+
const FUNC_ERROR_TEXT = 'Expected a function';
|
|
6
|
+
const nativeMax = Math.max;
|
|
7
|
+
const nativeMin = Math.min;
|
|
8
|
+
function debounce(func, wait = 0, options = {}) {
|
|
11
9
|
var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
|
|
12
10
|
if (typeof func != 'function') {
|
|
13
11
|
throw new TypeError(FUNC_ERROR_TEXT);
|
|
@@ -76,11 +74,7 @@ function debounce(func, wait, options) {
|
|
|
76
74
|
function flush() {
|
|
77
75
|
return timerId === undefined ? result : trailingEdge(Date.now());
|
|
78
76
|
}
|
|
79
|
-
function debounced() {
|
|
80
|
-
var debouncedArgs = [];
|
|
81
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
82
|
-
debouncedArgs[_i] = arguments[_i];
|
|
83
|
-
}
|
|
77
|
+
function debounced(...debouncedArgs) {
|
|
84
78
|
var time = Date.now(), isInvoking = shouldInvoke(time);
|
|
85
79
|
lastArgs = arguments;
|
|
86
80
|
lastThis = this;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
var run = function (task) { return new task_1.default(task).run(); };
|
|
11
|
-
exports.default = { sleep: sleep, run: run, debounce: debounce_1.default, throttle: throttle_1.default };
|
|
3
|
+
const debounce_1 = require("./debounce");
|
|
4
|
+
const throttle_1 = require("./throttle");
|
|
5
|
+
const task_1 = require("../../class/task");
|
|
6
|
+
const sleep = (time = 1000) => new Promise(resolve => { setTimeout(resolve, time); });
|
|
7
|
+
const run = (task) => new task_1.default(task).run();
|
|
8
|
+
exports.default = { sleep, run, debounce: debounce_1.default, throttle: throttle_1.default };
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const is_1 = require("../../util/is");
|
|
4
|
+
const debounce_1 = require("./debounce");
|
|
5
5
|
/** Error message constants. */
|
|
6
|
-
|
|
7
|
-
function throttle(func, wait, options) {
|
|
8
|
-
if (wait === void 0) { wait = 0; }
|
|
9
|
-
if (options === void 0) { options = {}; }
|
|
6
|
+
const FUNC_ERROR_TEXT = 'Expected a function';
|
|
7
|
+
function throttle(func, wait = 0, options = {}) {
|
|
10
8
|
var leading = false, trailing = true;
|
|
11
9
|
if (typeof func != 'function') {
|
|
12
10
|
throw new TypeError(FUNC_ERROR_TEXT);
|
package/bin/lib/modules/list.js
CHANGED
|
@@ -1,24 +1,69 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const is_1 = require("../util/is");
|
|
4
|
+
/**
|
|
5
|
+
* 分组
|
|
6
|
+
* @param list 列表
|
|
7
|
+
* @param key 关键字
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
const groupBy = (list, key) => {
|
|
11
|
+
return list.reduce((pre, current) => {
|
|
6
12
|
(pre[current[key]] = pre[current[key]] || []).push(current);
|
|
7
13
|
return pre;
|
|
8
14
|
}, {});
|
|
9
15
|
};
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
/**
|
|
17
|
+
* 分步动作
|
|
18
|
+
* @param list 列表
|
|
19
|
+
* @param func 动作function
|
|
20
|
+
* @param stepCount 每步数量
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
function stepAction(list, func, stepCount = 100) {
|
|
12
24
|
if (!is_1.default.isFunction(func))
|
|
13
25
|
return;
|
|
14
26
|
if (!is_1.default.isArray(list) || list.length <= 0)
|
|
15
27
|
return;
|
|
16
|
-
|
|
28
|
+
let start = 0;
|
|
17
29
|
while (list.length > start) {
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
let endIndex = stepCount + start;
|
|
31
|
+
let arr = list.slice(start, endIndex);
|
|
20
32
|
func && func(arr);
|
|
21
33
|
start = endIndex;
|
|
22
34
|
}
|
|
23
35
|
}
|
|
24
|
-
|
|
36
|
+
/**
|
|
37
|
+
* 跳过数据
|
|
38
|
+
* @param list 列表
|
|
39
|
+
* @param count 跳过数量
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
const skip = (list, count) => {
|
|
43
|
+
if (!is_1.default.isArray(list) || list.length <= 0)
|
|
44
|
+
return [];
|
|
45
|
+
const start = count;
|
|
46
|
+
return list.slice(start);
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* 提取数据
|
|
50
|
+
* @param list 列表
|
|
51
|
+
* @param count 提取数量
|
|
52
|
+
* @param skip 跳过数量
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
const take = (list, count, skip = 0) => {
|
|
56
|
+
if (!is_1.default.isArray(list) || list.length <= 0)
|
|
57
|
+
return [];
|
|
58
|
+
const start = skip || 0;
|
|
59
|
+
if (start >= list.length)
|
|
60
|
+
return [];
|
|
61
|
+
const endIndex = count + start;
|
|
62
|
+
return list.slice(start, list.length > endIndex ? list.length : endIndex) || [];
|
|
63
|
+
};
|
|
64
|
+
const distinct = (list) => {
|
|
65
|
+
if (!is_1.default.isArray(list) || list.length <= 0)
|
|
66
|
+
return [];
|
|
67
|
+
return [...new Set(list)];
|
|
68
|
+
};
|
|
69
|
+
exports.default = { groupBy, stepAction, skip, take, distinct };
|
package/bin/lib/modules/time.js
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const _root_1 = require("../common/_root");
|
|
4
4
|
/**
|
|
5
5
|
* 是否是今天
|
|
6
6
|
* @param {*} date
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
const isToday = (date) => new Date().toDateString() === new Date(date).toDateString();
|
|
10
10
|
/**
|
|
11
11
|
* 时间格式化
|
|
12
12
|
* @param {string|number|Date} time
|
|
13
13
|
* @param {string} reg "yyyyMMdd hhmmss"
|
|
14
14
|
* @returns
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var map = {};
|
|
16
|
+
const format = (time, reg = "yyyy-MM-dd hh:mm:ss") => {
|
|
17
|
+
const date = typeof time === "string" || typeof time === "number" ? new Date(time) : time;
|
|
18
|
+
const map = {};
|
|
20
19
|
map.yyyy = date.getFullYear();
|
|
21
|
-
map.yy =
|
|
20
|
+
map.yy = `${map.yyyy}`.substr(2);
|
|
22
21
|
map.M = date.getMonth() + 1;
|
|
23
22
|
map.MM = (map.M < 10 ? "0" : "") + map.M;
|
|
24
23
|
map.d = date.getDate();
|
|
@@ -32,15 +31,14 @@ var format = function (time, reg) {
|
|
|
32
31
|
map.S = date.getMilliseconds();
|
|
33
32
|
map.SS = (map.S < 10 ? "0" : "") + map.S;
|
|
34
33
|
map.SSS = map.S.toString().padStart(3, 0);
|
|
35
|
-
return reg.replace(/\byyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g,
|
|
34
|
+
return reg.replace(/\byyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g, ($1) => map[$1]);
|
|
36
35
|
};
|
|
37
|
-
function parseTime(
|
|
38
|
-
|
|
39
|
-
var _format = "".concat(year || "yyyy", "/").concat(month || "MM", "/").concat(date || "dd", " ").concat(hour, ":").concat(minute, ":").concat(second);
|
|
36
|
+
function parseTime({ year = 0, month = 0, date = 0, hour = 0, minute = 0, second = 0 }) {
|
|
37
|
+
const _format = `${year || "yyyy"}/${month || "MM"}/${date || "dd"} ${hour}:${minute}:${second}`;
|
|
40
38
|
return new Date(format(Date.now(), _format)).getTime();
|
|
41
39
|
}
|
|
42
40
|
function now() {
|
|
43
41
|
return _root_1.default.Date.now();
|
|
44
42
|
}
|
|
45
43
|
;
|
|
46
|
-
exports.default = { now
|
|
44
|
+
exports.default = { now, isToday, format, parseTime };
|
package/bin/lib/util/includes.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const is_1 = require("./is");
|
|
4
|
+
const to_1 = require("./to");
|
|
5
|
+
const _object_1 = require("../common/_object");
|
|
6
6
|
function arrayMap(array, iteratee) {
|
|
7
7
|
var index = -1, length = array ? array.length : 0, result = Array(length);
|
|
8
8
|
while (++index < length) {
|
package/bin/lib/util/index.js
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
exports.default =
|
|
3
|
+
const is_1 = require("./is");
|
|
4
|
+
const _object_1 = require("../common/_object");
|
|
5
|
+
const includes_1 = require("./includes");
|
|
6
|
+
exports.default = Object.assign(Object.assign(Object.assign({}, is_1.default), _object_1.default), { includes: includes_1.default });
|
package/bin/lib/util/is.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const _object_1 = require("../common/_object");
|
|
4
4
|
/** `Object#toString` result references. */
|
|
5
5
|
var argsTag = '[object Arguments]', funcTag = '[object Function]', genTag = '[object GeneratorFunction]', asyncTag = '[object AsyncFunction]', stringTag = '[object String]', promiseTag = '[object Promise]';
|
|
6
6
|
var MAX_SAFE_INTEGER = 9007199254740991, NAN = 0 / 0;
|
|
7
7
|
/** Used to detect unsigned integer values. */
|
|
8
|
-
|
|
8
|
+
const reIsUint = /^(?:0|[1-9]\d*)$/;
|
|
9
9
|
function is(val, type) {
|
|
10
|
-
return _object_1.default.getTag(val) ===
|
|
10
|
+
return _object_1.default.getTag(val) === `[object ${type}]`;
|
|
11
11
|
}
|
|
12
12
|
function isNumber(value) {
|
|
13
13
|
return _object_1.default.getTag(value) === "[object Number]";
|
|
@@ -19,14 +19,14 @@ function isString(value) {
|
|
|
19
19
|
function isChinese(content) {
|
|
20
20
|
if (!content)
|
|
21
21
|
return false;
|
|
22
|
-
|
|
22
|
+
const reg = /^[\u4E00-\u9FA5]+$/;
|
|
23
23
|
if (!reg.test(content)) {
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
28
|
function isObject(value) {
|
|
29
|
-
|
|
29
|
+
const type = typeof value;
|
|
30
30
|
return value != null && (type == "object" || type == "function");
|
|
31
31
|
}
|
|
32
32
|
function isObjectLike(value) {
|
|
@@ -35,7 +35,7 @@ function isObjectLike(value) {
|
|
|
35
35
|
function isSymbol(value) {
|
|
36
36
|
return typeof value === 'symbol' || (isObjectLike(value) && _object_1.default.getTag(value) === '[object Symbol]');
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
const isArray = Array.isArray;
|
|
39
39
|
function isArrayLike(value) {
|
|
40
40
|
return value != null && isLength(value.length) && !isFunction(value);
|
|
41
41
|
}
|
|
@@ -69,19 +69,19 @@ function isArguments(value) {
|
|
|
69
69
|
(!_object_1.default.propertyIsEnumerable.call(value, 'callee') || _object_1.default.toString.call(value) == argsTag);
|
|
70
70
|
}
|
|
71
71
|
exports.default = {
|
|
72
|
-
is
|
|
73
|
-
isNumber
|
|
74
|
-
isString
|
|
75
|
-
isChinese
|
|
76
|
-
isObject
|
|
77
|
-
isObjectLike
|
|
78
|
-
isSymbol
|
|
79
|
-
isFunction
|
|
80
|
-
isArray
|
|
81
|
-
isArrayLikeObject
|
|
82
|
-
isIndex
|
|
83
|
-
isArrayLike
|
|
84
|
-
isPrototype
|
|
85
|
-
isArguments
|
|
86
|
-
isPromise
|
|
72
|
+
is,
|
|
73
|
+
isNumber,
|
|
74
|
+
isString,
|
|
75
|
+
isChinese,
|
|
76
|
+
isObject,
|
|
77
|
+
isObjectLike,
|
|
78
|
+
isSymbol,
|
|
79
|
+
isFunction,
|
|
80
|
+
isArray,
|
|
81
|
+
isArrayLikeObject,
|
|
82
|
+
isIndex,
|
|
83
|
+
isArrayLike,
|
|
84
|
+
isPrototype,
|
|
85
|
+
isArguments,
|
|
86
|
+
isPromise
|
|
87
87
|
};
|
package/bin/lib/util/to.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
const is_1 = require("./is");
|
|
4
|
+
const NAN = 0 / 0;
|
|
5
|
+
const reTrim = /^\s+|\s+$/g;
|
|
6
|
+
const reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
|
|
7
|
+
const reIsBinary = /^0b[01]+$/i;
|
|
8
|
+
const reIsOctal = /^0o[0-7]+$/i;
|
|
9
|
+
const freeParseInt = parseInt;
|
|
10
|
+
const INFINITY = 1 / 0;
|
|
11
|
+
const MAX_INTEGER = 1.7976931348623157e+308;
|
|
12
12
|
function toNumber(value) {
|
|
13
13
|
if (typeof value == 'number') {
|
|
14
14
|
return value;
|
|
@@ -17,14 +17,14 @@ function toNumber(value) {
|
|
|
17
17
|
return NAN;
|
|
18
18
|
}
|
|
19
19
|
if (is_1.default.isObject(value)) {
|
|
20
|
-
|
|
20
|
+
const other = typeof value.valueOf == 'function' ? value.valueOf() : value;
|
|
21
21
|
value = is_1.default.isObject(other) ? (other + '') : other;
|
|
22
22
|
}
|
|
23
23
|
if (typeof value != 'string') {
|
|
24
24
|
return value === 0 ? value : +value;
|
|
25
25
|
}
|
|
26
26
|
value = value.replace(reTrim, '');
|
|
27
|
-
|
|
27
|
+
const isBinary = reIsBinary.test(value);
|
|
28
28
|
return (isBinary || reIsOctal.test(value))
|
|
29
29
|
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
|
|
30
30
|
: (reIsBadHex.test(value) ? NAN : +value);
|
|
@@ -44,4 +44,4 @@ function toInteger(value) {
|
|
|
44
44
|
var result = toFinite(value), remainder = result % 1;
|
|
45
45
|
return result === result ? (remainder ? result - remainder : result) : 0;
|
|
46
46
|
}
|
|
47
|
-
exports.default = { toNumber
|
|
47
|
+
exports.default = { toNumber, toFinite, toInteger };
|
package/bin/types/index.d.ts
CHANGED
|
@@ -60,7 +60,9 @@ declare const _default: {
|
|
|
60
60
|
};
|
|
61
61
|
list: {
|
|
62
62
|
groupBy: (list: any[], key: string) => Record<string, any[]>;
|
|
63
|
-
|
|
63
|
+
stepAction: <T>(list: T[], func: import("./typings").TArrayFunction<T>, stepCount?: number) => void;
|
|
64
|
+
skip: (list: any[], count: number) => any[];
|
|
65
|
+
take: (list: any[], count: number, skip?: number) => any[];
|
|
64
66
|
};
|
|
65
67
|
DEvent: typeof DEvent;
|
|
66
68
|
};
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { TArrayFunction } from "../typings";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* 分步动作
|
|
4
|
+
* @param list 列表
|
|
5
|
+
* @param func 动作function
|
|
6
|
+
* @param stepCount 每步数量
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
declare function stepAction<T>(list: T[], func: TArrayFunction<T>, stepCount?: number): void;
|
|
3
10
|
declare const _default: {
|
|
4
11
|
groupBy: (list: any[], key: string) => Record<string, any[]>;
|
|
5
|
-
|
|
12
|
+
stepAction: typeof stepAction;
|
|
13
|
+
skip: (list: any[], count: number) => any[];
|
|
14
|
+
take: (list: any[], count: number, skip?: number) => any[];
|
|
15
|
+
distinct: (list: any[]) => any[];
|
|
6
16
|
};
|
|
7
17
|
export default _default;
|