ddan-js 1.1.6 → 1.1.8
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/store.js +71 -0
- package/bin/lib/index.js +5 -2
- package/bin/types/class/store.d.ts +11 -0
- package/bin/types/index.d.ts +5 -1
- package/bin/types/typings/index.d.ts +6 -0
- package/package.json +1 -1
package/bin/ddan-js.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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]",
|
|
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]",d="[object AsyncFunction]",m=9007199254740991;const p=/^(?:0|[1-9]\d*)$/;function b(t){const e=typeof t;return null!=t&&("object"==e||"function"==e)}function v(t){return null!=t&&"object"==typeof t}const S=Array.isArray;function j(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=m}(t.length)&&!w(t)}function O(t){return v(t)&&j(t)}function w(t){var e=b(t)?h.getTag(t):"";return e===g||e===y||e===d}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||!S(t)&&v(t)&&"[object String]"==h.getTag(t)},isChinese:function(t){return!!t&&!!/^[\u4E00-\u9FA5]+$/.test(t)},isObject:b,isObjectLike:v,isSymbol:function(t){return"symbol"==typeof t||v(t)&&"[object Symbol]"===h.getTag(t)},isFunction:w,isArray:S,isArrayLikeObject:O,isIndex:function(t,e){return!!(e=null==e?m:e)&&("number"==typeof t||p.test(t))&&t>-1&&t%1==0&&t<e},isArrayLike:j,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]"===(b(t)?h.getTag(t):"")}};const M=NaN,T=/^\s+|\s+$/g,x=/^[-+]0x[0-9a-f]+$/i,P=/^0b[01]+$/i,$=/^0o[0-7]+$/i,D=parseInt,F=1/0,k=17976931348623157e292;function E(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=P.test(t);return e||$.test(t)?D(t.slice(2),e?2:8):x.test(t)?M:+t}function N(t){return t?(t=E(t))===F||t===-F?(t<0?-1:1)*k:t==t?t:0:0===t?t:0}var R={toNumber:E,toFinite:N,toInteger:function(t){var e=N(t),n=e%1;return e==e?n?e-n:e:0}};const _="Expected a function",I=Math.max,C=Math.min;function L(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(_);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?C(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=R.toNumber(e)||0,A.isObject(n)&&(f=!!n.leading,o=(l="maxWait"in n)?I(R.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 W{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 W(t).run(),debounce:L,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),L(t,e,{leading:r,maxWait:e,trailing:i})}};var J={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 U(t){return t!=t}function G(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 H,Y,q=(H=Object.keys,Y=Object,function(t){return H(Y(t))}),z=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)?G(i,function(t){return A.isArrayLike(t)?K(t):function(t){if(!A.isPrototype(t))return q(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?R.toInteger(n):0;var o=t.length;return n<0&&(n=z(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,U,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)]};function Z(t,e,n,r){return new(n||(n=Promise))((function(i,o){function u(t){try{c(r.next(t))}catch(t){o(t)}}function s(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,s)}c((r=r.apply(t,e||[])).next())}))}class tt extends V{constructor(){super(),this.getters={},this.setters={},this.actions={}}dispatch(t,e=void 0){return Z(this,void 0,void 0,(function*(){const n=Reflect.get(this.actions,t);if(!A.isFunction(n))return;const[,r]=yield B.run(n(this,e));return r}))}getByOnce(t){return Z(this,void 0,void 0,(function*(){const e=Reflect.get(this,t);let n;return n=null!=e&&""!==e?JSON.parse(JSON.stringify(e)):yield this.dispatch(t),n}))}}const et=t=>{const e=Object.assign(new tt,t||{});return new Proxy(e,{get:(t,e,n)=>{const r=Reflect.get(t.getters,e);return A.isFunction(r)?r():Reflect.get(t,e,n)},set:(t,e,n,r)=>{const i=Reflect.get(t.setters,e);if(A.isFunction(i)&&!i(n))return!0;const o=Reflect.set(t,e,n,r);return o&&t.emit(e.toString(),n),o},has:(t,e)=>Reflect.has(t,e)})};var nt={gbk:t,time:o,hook:B,math:J,util:Q,list:X,DEvent:V,store:tt,storeRef:et};export{V as DEvent,nt as default,t as gbk,B as hook,X as list,J as math,tt as store,et as storeRef,o as time,Q as util};
|
package/bin/ddan-js.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).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]",
|
|
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]",p="[object AsyncFunction]",m=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<=m}(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===p}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?m: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,x=/^\s+|\s+$/g,P=/^[-+]0x[0-9a-f]+$/i,k=/^0b[01]+$/i,D=/^0o[0-7]+$/i,$=parseInt,F=1/0,E=17976931348623157e292;function _(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(x,"");const e=k.test(t);return e||D.test(t)?$(t.slice(2),e?2:8):P.test(t)?T:+t}function N(t){return t?(t=_(t))===F||t===-F?(t<0?-1:1)*E:t==t?t:0:0===t?t:0}var R={toNumber:_,toFinite:N,toInteger:function(t){var e=N(t),n=e%1;return e==e?n?e-n:e:0}};const I="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(I);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 p(t);s=setTimeout(d,function(t){var n=e-(t-c);return l?L(n,o-(t-a)):n}(t))}function p(t){return s=void 0,h&&r?g(t):(r=i=void 0,u)}function m(...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=R.toNumber(e)||0,M.isObject(n)&&(f=!!n.leading,o=(l="maxWait"in n)?C(R.toNumber(n.maxWait)||0,e):o,h="trailing"in n?!!n.trailing:h),m.cancel=function(){void 0!==s&&clearTimeout(s),a=0,r=c=i=s=void 0},m.flush=function(){return void 0===s?u:p(Date.now())},m}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 J={sleep:(t=1e3)=>new Promise((e=>{setTimeout(e,t)})),run:t=>new B(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 M.isObject(n)&&(r=n.leading?!!n.leading:r,i=n.trailing?!!n.trailing:i),W(t,e,{leading:r,maxWait:e,trailing:i})}};var U={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 G(t){return t!=t}function H(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))}),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)?H(i,function(t){return M.isArrayLike(t)?Q(t):function(t){if(!M.isPrototype(t))return z(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?R.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,G,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)]};function tt(t,e,n,r){return new(n||(n=Promise))((function(i,o){function u(t){try{c(r.next(t))}catch(t){o(t)}}function s(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,s)}c((r=r.apply(t,e||[])).next())}))}class et extends X{constructor(){super(),this.getters={},this.setters={},this.actions={}}dispatch(t,e=void 0){return tt(this,void 0,void 0,(function*(){const n=Reflect.get(this.actions,t);if(!M.isFunction(n))return;const[,r]=yield J.run(n(this,e));return r}))}getByOnce(t){return tt(this,void 0,void 0,(function*(){const e=Reflect.get(this,t);let n;return n=null!=e&&""!==e?JSON.parse(JSON.stringify(e)):yield this.dispatch(t),n}))}}const nt=t=>{const e=Object.assign(new et,t||{});return new Proxy(e,{get:(t,e,n)=>{const r=Reflect.get(t.getters,e);return M.isFunction(r)?r():Reflect.get(t,e,n)},set:(t,e,n,r)=>{const i=Reflect.get(t.setters,e);if(M.isFunction(i)&&!i(n))return!0;const o=Reflect.set(t,e,n,r);return o&&t.emit(e.toString(),n),o},has:(t,e)=>Reflect.has(t,e)})};var rt={gbk:e,time:u,hook:J,math:U,util:V,list:Z,DEvent:X,store:et,storeRef:nt};t.DEvent=X,t.default=rt,t.gbk=e,t.hook=J,t.list=Z,t.math=U,t.store=et,t.storeRef=nt,t.time=u,t.util=V,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.storeRef = void 0;
|
|
13
|
+
const hook_1 = require("../modules/hook");
|
|
14
|
+
const event_1 = require("./event");
|
|
15
|
+
const is_1 = require("../util/is");
|
|
16
|
+
class DStore extends event_1.default {
|
|
17
|
+
constructor() {
|
|
18
|
+
super();
|
|
19
|
+
this.getters = {};
|
|
20
|
+
this.setters = {};
|
|
21
|
+
this.actions = {};
|
|
22
|
+
}
|
|
23
|
+
dispatch(key, payload = undefined) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const self = this;
|
|
26
|
+
const action = Reflect.get(this.actions, key);
|
|
27
|
+
if (!is_1.default.isFunction(action))
|
|
28
|
+
return undefined;
|
|
29
|
+
// return Promise.resolve().then(() => action(self, payload));
|
|
30
|
+
const [, data] = yield hook_1.default.run(action(self, payload));
|
|
31
|
+
return data;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
getByOnce(key) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const val = Reflect.get(this, key);
|
|
37
|
+
let result = undefined;
|
|
38
|
+
if (val !== null && val !== undefined && val !== "") {
|
|
39
|
+
result = JSON.parse(JSON.stringify(val));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
result = yield this.dispatch(key);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.default = DStore;
|
|
49
|
+
const storeRef = (source) => {
|
|
50
|
+
const _source = Object.assign(new DStore(), source || {});
|
|
51
|
+
return new Proxy(_source, {
|
|
52
|
+
get: (target, key, receiver) => {
|
|
53
|
+
const getFunc = Reflect.get(target.getters, key);
|
|
54
|
+
if (is_1.default.isFunction(getFunc))
|
|
55
|
+
return getFunc();
|
|
56
|
+
return Reflect.get(target, key, receiver);
|
|
57
|
+
},
|
|
58
|
+
set: (target, key, value, receiver) => {
|
|
59
|
+
const setFunc = Reflect.get(target.setters, key);
|
|
60
|
+
if (is_1.default.isFunction(setFunc) && !setFunc(value))
|
|
61
|
+
return true;
|
|
62
|
+
const ret = Reflect.set(target, key, value, receiver);
|
|
63
|
+
if (ret) {
|
|
64
|
+
target.emit(key.toString(), value);
|
|
65
|
+
}
|
|
66
|
+
return ret;
|
|
67
|
+
},
|
|
68
|
+
has: (target, key) => Reflect.has(target, key),
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
exports.storeRef = storeRef;
|
package/bin/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEvent = exports.list = exports.util = exports.math = exports.hook = exports.time = exports.gbk = void 0;
|
|
3
|
+
exports.storeRef = exports.store = 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");
|
|
@@ -15,4 +15,7 @@ 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
|
+
const store_1 = require("./class/store");
|
|
19
|
+
exports.store = store_1.default;
|
|
20
|
+
Object.defineProperty(exports, "storeRef", { enumerable: true, get: function () { return store_1.storeRef; } });
|
|
21
|
+
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, store: store_1.default, storeRef: store_1.storeRef };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import DEvent from "./event";
|
|
2
|
+
import { IDStore } from "../typings";
|
|
3
|
+
export default class DStore extends DEvent {
|
|
4
|
+
actions: {};
|
|
5
|
+
setters: {};
|
|
6
|
+
getters: {};
|
|
7
|
+
constructor();
|
|
8
|
+
dispatch(key: string, payload?: undefined): Promise<any>;
|
|
9
|
+
getByOnce(key: string): Promise<undefined>;
|
|
10
|
+
}
|
|
11
|
+
export declare const storeRef: (source: IDStore) => DStore & IDStore;
|
package/bin/types/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ import math from "./modules/math";
|
|
|
5
5
|
import util from "./util";
|
|
6
6
|
import DEvent from "./class/event";
|
|
7
7
|
import list from "./modules/list";
|
|
8
|
-
|
|
8
|
+
import store, { storeRef } from "./class/store";
|
|
9
|
+
export { gbk, time, hook, math, util, list, DEvent, store, storeRef };
|
|
9
10
|
declare const _default: {
|
|
10
11
|
gbk: {
|
|
11
12
|
gbkLength: (str: string) => number;
|
|
@@ -63,7 +64,10 @@ declare const _default: {
|
|
|
63
64
|
stepAction: <T>(list: T[], func: import("./typings").TArrayFunction<T>, stepCount?: number) => void;
|
|
64
65
|
skip: (list: any[], count: number) => any[];
|
|
65
66
|
take: (list: any[], count: number, skip?: number) => any[];
|
|
67
|
+
distinct: (list: any[]) => any[];
|
|
66
68
|
};
|
|
67
69
|
DEvent: typeof DEvent;
|
|
70
|
+
store: typeof store;
|
|
71
|
+
storeRef: (source: import("./typings").IDStore) => store & import("./typings").IDStore;
|
|
68
72
|
};
|
|
69
73
|
export default _default;
|