ddan-js 1.2.0 → 1.2.2
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/index.js +3 -1
- package/bin/lib/modules/mini/diff.js +91 -0
- package/bin/lib/modules/mini/index.js +20 -0
- package/bin/lib/modules/url/decode.js +45 -0
- package/bin/lib/modules/url/encode.js +38 -0
- package/bin/lib/modules/url/index.js +5 -0
- package/bin/types/index.d.ts +11 -0
- package/bin/types/modules/mini/diff.d.ts +1 -0
- package/bin/types/modules/mini/index.d.ts +7 -0
- package/bin/types/modules/url/decode.d.ts +7 -0
- package/bin/types/modules/url/encode.d.ts +7 -0
- package/bin/types/modules/url/index.d.ts +7 -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]))};function o(){return r.Date.now()}var u={now:o,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()},todayZero:()=>new Date(i(o(),"yyyy/MM/dd 00:00:00")).getTime(),oneDay:864e5,oneHour:36e5,oneMinute:6e4,oneSecond:1e3};const s=r.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 S(t){return null!=t&&"object"==typeof t}const j=Array.isArray;function O(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=p}(t.length)&&!M(t)}function w(t){return S(t)&&O(t)}function M(t){var e=v(t)?g.getTag(t):"";return e===y||e===d||e===m}var A={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||!j(t)&&S(t)&&"[object String]"==g.getTag(t)},isChinese:function(t){return!!t&&!!/^[\u4E00-\u9FA5]+$/.test(t)},isObject:v,isObjectLike:S,isSymbol:function(t){return"symbol"==typeof t||S(t)&&"[object Symbol]"===g.getTag(t)},isFunction:M,isArray:j,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,x=/^\s+|\s+$/g,D=/^[-+]0x[0-9a-f]+$/i,P=/^0b[01]+$/i,$=/^0o[0-7]+$/i,F=parseInt,k=1/0,E=17976931348623157e292;function N(t){if("number"==typeof t)return t;if(A.isSymbol(t))return T;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(x,"");const e=P.test(t);return e||$.test(t)?F(t.slice(2),e?2:8):D.test(t)?T:+t}function R(t){return t?(t=N(t))===k||t===-k?(t<0?-1:1)*E:t==t?t:0:0===t?t:0}var _={toNumber:N,toFinite:R,toInteger:function(t){var e=R(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 m(t);s=setTimeout(d,function(t){var n=e-(t-c);return l?L(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=_.toNumber(e)||0,A.isObject(n)&&(f=!!n.leading,o=(l="maxWait"in n)?C(_.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=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 H={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 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 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 Y,Z,q=(Y=Object.keys,Z=Object,function(t){return Y(Z(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&&!g.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),g),{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))g.hasOwnProperty.call(t,n)&&"constructor"!=n&&e.push(n);return e}(t)}(i)):[],n=n&&!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 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 V{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(!A.isFunction(n))return;const[,r]=yield H.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}))}}var nt={gbk:t,time:u,hook:H,math:J,util:Q,list:X,DEvent:V,store:et,storeRef:t=>{const e=Object.assign(new et,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)})}};export{nt as default};
|
|
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 o=0;o<t.length&&(t.charCodeAt(o)>127||94===t.charCodeAt(o)?n+=2:n++,!(n>e));o++)r=o;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 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]))};function i(){return r.Date.now()}var s={now:i,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:s=0}){const c=`${t||"yyyy"}/${e||"MM"}/${n||"dd"} ${r}:${i}:${s}`;return new Date(o(Date.now(),c)).getTime()},todayZero:()=>new Date(o(i(),"yyyy/MM/dd 00:00:00")).getTime(),oneDay:864e5,oneHour:36e5,oneMinute:6e4,oneSecond:1e3};const c=r.Symbol,{toString:u,hasOwnProperty:a,propertyIsEnumerable:l}=Object.prototype,f=c?c.toStringTag:void 0;function h(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":f&&f in Object(t)?function(t){const e=a.call(t,f),n=t[f];let r=!1;try{t[f]=void 0,r=!0}catch(t){}const o=u.call(t);return r&&(e?t[f]=n:delete t[f]),o}(t):u.call(t)}var g={getTag:h,getType:function(t){return(h(t).match(/\w+/g)||["object","Undefined"])[1]||""},toString:u,hasOwnProperty:a,propertyIsEnumerable:l},y="[object Function]",p="[object GeneratorFunction]",d="[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 O=Array.isArray;function S(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)&&S(t)}function A(t){var e=v(t)?g.getTag(t):"";return e===y||e===p||e===d}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||!O(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:O,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:S,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 $=NaN,T=/^\s+|\s+$/g,k=/^[-+]0x[0-9a-f]+$/i,x=/^0b[01]+$/i,P=/^0o[0-7]+$/i,R=parseInt,D=1/0,I=17976931348623157e292;function F(t){if("number"==typeof t)return t;if(M.isSymbol(t))return $;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(T,"");const e=x.test(t);return e||P.test(t)?R(t.slice(2),e?2:8):k.test(t)?$:+t}function C(t){return t?(t=F(t))===D||t===-D?(t<0?-1:1)*I:t==t?t:0:0===t?t:0}var E={toNumber:F,toFinite:C,toInteger:function(t){var e=C(t),n=e%1;return e==e?n?e-n:e:0}};const N="Expected a function",U=Math.max,_=Math.min;function L(t,e=0,n={}){var r,o,i,s,c,u,a=0,l=!1,f=!1,h=!0;if("function"!=typeof t)throw new TypeError(N);function g(e){var n=r,i=o;return r=o=void 0,a=e,s=t.apply(i,n)}function y(t){var n=t-u;return void 0===u||n>=e||n<0||f&&t-a>=i}function p(){var t=Date.now();if(y(t))return d(t);c=setTimeout(p,function(t){var n=e-(t-u);return f?_(n,i-(t-a)):n}(t))}function d(t){return c=void 0,h&&r?g(t):(r=o=void 0,s)}function m(...t){var n=Date.now(),i=y(n);if(r=arguments,o=this,u=n,i){if(void 0===c)return function(t){return a=t,c=setTimeout(p,e),l?g(t):s}(u);if(f)return c=setTimeout(p,e),g(u)}return void 0===c&&(c=setTimeout(p,e)),s}return e=E.toNumber(e)||0,M.isObject(n)&&(l=!!n.leading,i=(f="maxWait"in n)?U(E.toNumber(n.maxWait)||0,e):i,h="trailing"in n?!!n.trailing:h),m.cancel=function(){void 0!==c&&clearTimeout(c),a=0,r=u=o=c=void 0},m.flush=function(){return void 0===c?s:d(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 W={sleep:(t=1e3)=>new Promise((e=>{setTimeout(e,t)})),run:t=>new B(t).run(),debounce:L,throttle:function(t,e=0,n={}){var r=!1,o=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return M.isObject(n)&&(r=n.leading?!!n.leading:r,o=n.trailing?!!n.trailing:o),L(t,e,{leading:r,maxWait:e,trailing:o})}};var q={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 J(t,e){return function(t,e){for(var n=-1,r=t?t.length:0,o=Array(r);++n<r;)o[n]=e(t[n],n,t);return o}(e,(function(e){return t[e]}))}var G,Y,Z=(G=Object.keys,Y=Object,function(t){return G(Y(t))}),z=Math.max;function K(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,o=!!r;for(var i in t)!e&&!g.hasOwnProperty.call(t,i)||o&&("length"==i||M.isIndex(i,r))||n.push(i);return n}var Q=Object.assign(Object.assign(Object.assign({},M),g),{includes:function(t,e,n,r){var o;t=M.isArrayLike(t)?t:(o=t)?J(o,function(t){return M.isArrayLike(t)?K(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)}(o)):[],n=n&&!r?E.toInteger(n):0;var i=t.length;return n<0&&(n=z(i+n,0)),M.isString(t)?n<=i&&t.indexOf(e,n)>-1:!!i&&function(t,e,n){if(e!=e)return function(t,e,n,r){for(var o=t.length,i=n+(r?1:-1);r?i--:++i<o;)if(e(t[i],i,t))return i;return-1}(t,H,n);for(var r=n-1,o=t.length;++r<o;)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(!M.isFunction(e))return;if(!M.isArray(t)||t.length<=0)return;let r=0;for(;t.length>r;){let o=n+r,i=t.slice(r,o);e&&e(i),r=o}},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 o=e+r;return t.slice(r,t.length<o?t.length:o)||[]},distinct:t=>!M.isArray(t)||t.length<=0?[]:[...new Set(t)]};const tt="[object Object]",et="[object Array]",nt=t=>Object.prototype.toString.call(t),rt=(t,e,n=!1)=>{if(t===e)return;const r=nt(t);if(r===nt(e))if(r===et&&t.length>=e.length)for(let n=0;n<e.length;n++)rt(t[n],e[n]);else if(r===tt&&Object.keys(t).length>=Object.keys(e).length)for(let r in e)n||void 0!==t[r]?rt(t[r],e[r]):t[r]=null},ot=(t,e,n,r="",o=!1)=>{if(t===e)return;const i=nt(t),s=nt(e);if(i===et&&s===i&&t.length>=e.length)for(let o=0;o<t.length;o++)ot(t[o],e[o],n,`${r}[${o}]`);else if(i===tt&&s===i&&(o||Object.keys(t).length>=Object.keys(e).length)){const o=Object.keys(t);for(let i of o){const o=t[i],s=e[i],c=nt(o),u=nt(s);if(o!==s)if(c===et&&u===c&&o.length>=s.length)for(let t=0;t<o.length;t++)ot(o[t],s[t],n,`${r?r+".":""}${i}[${t}]`);else if(c===tt&&u===c&&Object.keys(o).length>=Object.keys(s).length)for(let t in o)ot(o[t],s[t],n,`${r?r+".":""}${i}.${t}`);else n[`${r?r+".":""}${i}`]=o}}else n[r]=t};const it=t=>(e,...n)=>new Promise(((r,o)=>{t(Object.assign({},e,{success:r,fail:o}),...n)}));var st={diff:function(t,e){const n={};return(t=>{if(nt(t)===tt)for(let e in t)if(/\w+\.\w+/g.test(e)&&-1===e.indexOf("[")){const n=e.split(".");let r=t,o=n.length;for(let t=0;t<o-1;t++){const e=n[t];nt(r[e])!==tt&&(r[e]={}),r=r[e]}r[n[o-1]]=t[e],delete t[e]}})(t),rt(t,e,!0),ot(t,e,n,"",!0),n},promixify:it,api:(t,e=null,...n)=>W.run(it(t)(e,...n))};function ct(t,e){return Object.prototype.hasOwnProperty.call(t,e)}const ut=function(t,{sep:e="&",eq:n="=",max:r=1e3,multiple:o=!1}={}){e=e||"&",n=n||"=";const i={};if("string"!=typeof t||0===t.length)return i;const s=/\+/g,c=r||1e3;let u=(t=t.split(e)).length;c>0&&u>c&&(u=c);for(let e=0;e<u;++e){let r,c,u,a,l=t[e].replace(s,"%20"),f=l.indexOf(n);f>=0?(r=l.substr(0,f),c=l.substr(f+1)):(r=l,c=""),u=decodeURIComponent(r),a=decodeURIComponent(c),ct(i,u)&&o?Array.isArray(i[u])?i[u].push(a):i[u]=[i[u],a]:i[u]=a}return i},at=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}},lt=function(t,{sep:e="&",eq:n="=",name:r=null,multiple:o=!1}={}){return e=e||"&",n=n||"=",null===t&&(t=void 0),"object"==typeof t?Object.keys(t).map((function(r){const i=encodeURIComponent(at(r))+n;return o&&Array.isArray(t[r])?t[r].map((function(t){return i+encodeURIComponent(at(t))})).join(e):i+encodeURIComponent(at(t[r]))})).filter(Boolean).join(e):r?encodeURIComponent(at(r))+n+encodeURIComponent(at(t)):""};var ft={parse:ut,decode:ut,stringify:lt,encode:lt};function ht(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{u(r.next(t))}catch(t){i(t)}}function c(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,c)}u((r=r.apply(t,e||[])).next())}))}class gt extends V{constructor(){super(),this.getters={},this.setters={},this.actions={}}dispatch(t,e=void 0){return ht(this,void 0,void 0,(function*(){const n=Reflect.get(this.actions,t);if(!M.isFunction(n))return;const[,r]=yield W.run(n(this,e));return r}))}getByOnce(t){return ht(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}))}}var yt={gbk:t,time:s,hook:W,math:q,util:Q,list:X,mini:st,url:ft,DEvent:V,store:gt,storeRef:t=>{const e=Object.assign(new gt,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 o=Reflect.get(t.setters,e);if(M.isFunction(o)&&!o(n))return!0;const i=Reflect.set(t,e,n,r);return i&&t.emit(e.toString(),n),i},has:(t,e)=>Reflect.has(t,e)})}};export{yt as default};
|
package/bin/ddan-js.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).ddan=e()}(this,(function(){"use strict";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]))};function o(){return r.Date.now()}var u={now:o,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()},todayZero:()=>new Date(i(o(),"yyyy/MM/dd 00:00:00")).getTime(),oneDay:864e5,oneHour:36e5,oneMinute:6e4,oneSecond:1e3};const s=r.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 S(t){return null!=t&&"object"==typeof t}const j=Array.isArray;function O(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=m}(t.length)&&!M(t)}function w(t){return S(t)&&O(t)}function M(t){var e=v(t)?g.getTag(t):"";return e===y||e===d||e===p}var A={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||!j(t)&&S(t)&&"[object String]"==g.getTag(t)},isChinese:function(t){return!!t&&!!/^[\u4E00-\u9FA5]+$/.test(t)},isObject:v,isObjectLike:S,isSymbol:function(t){return"symbol"==typeof t||S(t)&&"[object Symbol]"===g.getTag(t)},isFunction:M,isArray:j,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,D=/^[-+]0x[0-9a-f]+$/i,P=/^0b[01]+$/i,$=/^0o[0-7]+$/i,F=parseInt,k=1/0,E=17976931348623157e292;function N(t){if("number"==typeof t)return t;if(A.isSymbol(t))return T;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(x,"");const e=P.test(t);return e||$.test(t)?F(t.slice(2),e?2:8):D.test(t)?T:+t}function R(t){return t?(t=N(t))===k||t===-k?(t<0?-1:1)*E:t==t?t:0:0===t?t:0}var _={toNumber:N,toFinite:R,toInteger:function(t){var e=R(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=_.toNumber(e)||0,A.isObject(n)&&(f=!!n.leading,o=(l="maxWait"in n)?C(_.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=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 H={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 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 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 Y,Z,q=(Y=Object.keys,Z=Object,function(t){return Y(Z(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&&!g.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),g),{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))g.hasOwnProperty.call(t,n)&&"constructor"!=n&&e.push(n);return e}(t)}(i)):[],n=n&&!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 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 V{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(!A.isFunction(n))return;const[,r]=yield H.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}))}}return{gbk:t,time:u,hook:H,math:J,util:Q,list:X,DEvent:V,store:et,storeRef:t=>{const e=Object.assign(new et,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)})}}}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).ddan=e()}(this,(function(){"use strict";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 o=0;o<t.length&&(t.charCodeAt(o)>127||94===t.charCodeAt(o)?n+=2:n++,!(n>e));o++)r=o;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 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]))};function i(){return r.Date.now()}var s={now:i,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:s=0}){const u=`${t||"yyyy"}/${e||"MM"}/${n||"dd"} ${r}:${i}:${s}`;return new Date(o(Date.now(),u)).getTime()},todayZero:()=>new Date(o(i(),"yyyy/MM/dd 00:00:00")).getTime(),oneDay:864e5,oneHour:36e5,oneMinute:6e4,oneSecond:1e3};const u=r.Symbol,{toString:c,hasOwnProperty:a,propertyIsEnumerable:l}=Object.prototype,f=u?u.toStringTag:void 0;function h(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":f&&f in Object(t)?function(t){const e=a.call(t,f),n=t[f];let r=!1;try{t[f]=void 0,r=!0}catch(t){}const o=c.call(t);return r&&(e?t[f]=n:delete t[f]),o}(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:l},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 O=Array.isArray;function S(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)&&S(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||!O(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:O,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:S,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 $=NaN,T=/^\s+|\s+$/g,x=/^[-+]0x[0-9a-f]+$/i,k=/^0b[01]+$/i,P=/^0o[0-7]+$/i,R=parseInt,D=1/0,I=17976931348623157e292;function F(t){if("number"==typeof t)return t;if(M.isSymbol(t))return $;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(T,"");const e=k.test(t);return e||P.test(t)?R(t.slice(2),e?2:8):x.test(t)?$:+t}function C(t){return t?(t=F(t))===D||t===-D?(t<0?-1:1)*I:t==t?t:0:0===t?t:0}var E={toNumber:F,toFinite:C,toInteger:function(t){var e=C(t),n=e%1;return e==e?n?e-n:e:0}};const N="Expected a function",U=Math.max,_=Math.min;function L(t,e=0,n={}){var r,o,i,s,u,c,a=0,l=!1,f=!1,h=!0;if("function"!=typeof t)throw new TypeError(N);function g(e){var n=r,i=o;return r=o=void 0,a=e,s=t.apply(i,n)}function y(t){var n=t-c;return void 0===c||n>=e||n<0||f&&t-a>=i}function d(){var t=Date.now();if(y(t))return p(t);u=setTimeout(d,function(t){var n=e-(t-c);return f?_(n,i-(t-a)):n}(t))}function p(t){return u=void 0,h&&r?g(t):(r=o=void 0,s)}function m(...t){var n=Date.now(),i=y(n);if(r=arguments,o=this,c=n,i){if(void 0===u)return function(t){return a=t,u=setTimeout(d,e),l?g(t):s}(c);if(f)return u=setTimeout(d,e),g(c)}return void 0===u&&(u=setTimeout(d,e)),s}return e=E.toNumber(e)||0,M.isObject(n)&&(l=!!n.leading,i=(f="maxWait"in n)?U(E.toNumber(n.maxWait)||0,e):i,h="trailing"in n?!!n.trailing:h),m.cancel=function(){void 0!==u&&clearTimeout(u),a=0,r=c=o=u=void 0},m.flush=function(){return void 0===u?s: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 W={sleep:(t=1e3)=>new Promise((e=>{setTimeout(e,t)})),run:t=>new B(t).run(),debounce:L,throttle:function(t,e=0,n={}){var r=!1,o=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return M.isObject(n)&&(r=n.leading?!!n.leading:r,o=n.trailing?!!n.trailing:o),L(t,e,{leading:r,maxWait:e,trailing:o})}};var q={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 J(t,e){return function(t,e){for(var n=-1,r=t?t.length:0,o=Array(r);++n<r;)o[n]=e(t[n],n,t);return o}(e,(function(e){return t[e]}))}var G,Y,Z=(G=Object.keys,Y=Object,function(t){return G(Y(t))}),z=Math.max;function K(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,o=!!r;for(var i in t)!e&&!g.hasOwnProperty.call(t,i)||o&&("length"==i||M.isIndex(i,r))||n.push(i);return n}var Q=Object.assign(Object.assign(Object.assign({},M),g),{includes:function(t,e,n,r){var o;t=M.isArrayLike(t)?t:(o=t)?J(o,function(t){return M.isArrayLike(t)?K(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)}(o)):[],n=n&&!r?E.toInteger(n):0;var i=t.length;return n<0&&(n=z(i+n,0)),M.isString(t)?n<=i&&t.indexOf(e,n)>-1:!!i&&function(t,e,n){if(e!=e)return function(t,e,n,r){for(var o=t.length,i=n+(r?1:-1);r?i--:++i<o;)if(e(t[i],i,t))return i;return-1}(t,H,n);for(var r=n-1,o=t.length;++r<o;)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(!M.isFunction(e))return;if(!M.isArray(t)||t.length<=0)return;let r=0;for(;t.length>r;){let o=n+r,i=t.slice(r,o);e&&e(i),r=o}},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 o=e+r;return t.slice(r,t.length<o?t.length:o)||[]},distinct:t=>!M.isArray(t)||t.length<=0?[]:[...new Set(t)]};const tt="[object Object]",et="[object Array]",nt=t=>Object.prototype.toString.call(t),rt=(t,e,n=!1)=>{if(t===e)return;const r=nt(t);if(r===nt(e))if(r===et&&t.length>=e.length)for(let n=0;n<e.length;n++)rt(t[n],e[n]);else if(r===tt&&Object.keys(t).length>=Object.keys(e).length)for(let r in e)n||void 0!==t[r]?rt(t[r],e[r]):t[r]=null},ot=(t,e,n,r="",o=!1)=>{if(t===e)return;const i=nt(t),s=nt(e);if(i===et&&s===i&&t.length>=e.length)for(let o=0;o<t.length;o++)ot(t[o],e[o],n,`${r}[${o}]`);else if(i===tt&&s===i&&(o||Object.keys(t).length>=Object.keys(e).length)){const o=Object.keys(t);for(let i of o){const o=t[i],s=e[i],u=nt(o),c=nt(s);if(o!==s)if(u===et&&c===u&&o.length>=s.length)for(let t=0;t<o.length;t++)ot(o[t],s[t],n,`${r?r+".":""}${i}[${t}]`);else if(u===tt&&c===u&&Object.keys(o).length>=Object.keys(s).length)for(let t in o)ot(o[t],s[t],n,`${r?r+".":""}${i}.${t}`);else n[`${r?r+".":""}${i}`]=o}}else n[r]=t};const it=t=>(e,...n)=>new Promise(((r,o)=>{t(Object.assign({},e,{success:r,fail:o}),...n)}));var st={diff:function(t,e){const n={};return(t=>{if(nt(t)===tt)for(let e in t)if(/\w+\.\w+/g.test(e)&&-1===e.indexOf("[")){const n=e.split(".");let r=t,o=n.length;for(let t=0;t<o-1;t++){const e=n[t];nt(r[e])!==tt&&(r[e]={}),r=r[e]}r[n[o-1]]=t[e],delete t[e]}})(t),rt(t,e,!0),ot(t,e,n,"",!0),n},promixify:it,api:(t,e=null,...n)=>W.run(it(t)(e,...n))};function ut(t,e){return Object.prototype.hasOwnProperty.call(t,e)}const ct=function(t,{sep:e="&",eq:n="=",max:r=1e3,multiple:o=!1}={}){e=e||"&",n=n||"=";const i={};if("string"!=typeof t||0===t.length)return i;const s=/\+/g,u=r||1e3;let c=(t=t.split(e)).length;u>0&&c>u&&(c=u);for(let e=0;e<c;++e){let r,u,c,a,l=t[e].replace(s,"%20"),f=l.indexOf(n);f>=0?(r=l.substr(0,f),u=l.substr(f+1)):(r=l,u=""),c=decodeURIComponent(r),a=decodeURIComponent(u),ut(i,c)&&o?Array.isArray(i[c])?i[c].push(a):i[c]=[i[c],a]:i[c]=a}return i},at=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}},lt=function(t,{sep:e="&",eq:n="=",name:r=null,multiple:o=!1}={}){return e=e||"&",n=n||"=",null===t&&(t=void 0),"object"==typeof t?Object.keys(t).map((function(r){const i=encodeURIComponent(at(r))+n;return o&&Array.isArray(t[r])?t[r].map((function(t){return i+encodeURIComponent(at(t))})).join(e):i+encodeURIComponent(at(t[r]))})).filter(Boolean).join(e):r?encodeURIComponent(at(r))+n+encodeURIComponent(at(t)):""};var ft={parse:ct,decode:ct,stringify:lt,encode:lt};function ht(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function u(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}c((r=r.apply(t,e||[])).next())}))}class gt extends V{constructor(){super(),this.getters={},this.setters={},this.actions={}}dispatch(t,e=void 0){return ht(this,void 0,void 0,(function*(){const n=Reflect.get(this.actions,t);if(!M.isFunction(n))return;const[,r]=yield W.run(n(this,e));return r}))}getByOnce(t){return ht(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}))}}return{gbk:t,time:s,hook:W,math:q,util:Q,list:X,mini:st,url:ft,DEvent:V,store:gt,storeRef:t=>{const e=Object.assign(new gt,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 o=Reflect.get(t.setters,e);if(M.isFunction(o)&&!o(n))return!0;const i=Reflect.set(t,e,n,r);return i&&t.emit(e.toString(),n),i},has:(t,e)=>Reflect.has(t,e)})}}}));
|
package/bin/lib/index.js
CHANGED
|
@@ -7,6 +7,8 @@ const math_1 = require("./modules/math");
|
|
|
7
7
|
const util_1 = require("./util");
|
|
8
8
|
const event_1 = require("./class/event");
|
|
9
9
|
const list_1 = require("./modules/list");
|
|
10
|
+
const mini_1 = require("./modules/mini");
|
|
11
|
+
const url_1 = require("./modules/url");
|
|
10
12
|
const store_1 = require("./class/store");
|
|
11
13
|
// export { gbk, time, hook, math, util, list, DEvent, store, storeRef };
|
|
12
|
-
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 };
|
|
14
|
+
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, mini: mini_1.default, url: url_1.default, DEvent: event_1.default, store: store_1.default, storeRef: store_1.storeRef };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const OBJECT_TYPE = "[object Object]";
|
|
4
|
+
const ARRAY_TYPE = "[object Array]";
|
|
5
|
+
const getType = (obj) => Object.prototype.toString.call(obj);
|
|
6
|
+
const initPath = (data) => {
|
|
7
|
+
if (getType(data) !== OBJECT_TYPE)
|
|
8
|
+
return;
|
|
9
|
+
for (let item in data) {
|
|
10
|
+
if (/\w+\.\w+/g.test(item) && item.indexOf("[") === -1) {
|
|
11
|
+
const arr = item.split(".");
|
|
12
|
+
let result = data, len = arr.length;
|
|
13
|
+
for (let i = 0; i < len - 1; i++) {
|
|
14
|
+
const arrItem = arr[i];
|
|
15
|
+
if (getType(result[arrItem]) !== OBJECT_TYPE) {
|
|
16
|
+
result[arrItem] = {};
|
|
17
|
+
}
|
|
18
|
+
result = result[arrItem];
|
|
19
|
+
}
|
|
20
|
+
result[arr[len - 1]] = data[item];
|
|
21
|
+
delete data[item];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const initData = (cur, pre, root = false) => {
|
|
26
|
+
if (cur === pre)
|
|
27
|
+
return;
|
|
28
|
+
const curType = getType(cur), preType = getType(pre);
|
|
29
|
+
if (curType !== preType)
|
|
30
|
+
return;
|
|
31
|
+
if (curType === ARRAY_TYPE && cur.length >= pre.length) {
|
|
32
|
+
for (let i = 0; i < pre.length; i++) {
|
|
33
|
+
initData(cur[i], pre[i]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (curType === OBJECT_TYPE && Object.keys(cur).length >= Object.keys(pre).length) {
|
|
37
|
+
for (let key in pre) {
|
|
38
|
+
if (!root && cur[key] === undefined) {
|
|
39
|
+
cur[key] = null;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
initData(cur[key], pre[key]);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const doDiff = (cur, pre, target, path = "", root = false) => {
|
|
48
|
+
if (cur === pre)
|
|
49
|
+
return;
|
|
50
|
+
const curRootType = getType(cur), preRootType = getType(pre);
|
|
51
|
+
if (curRootType === ARRAY_TYPE && preRootType === curRootType && cur.length >= pre.length) {
|
|
52
|
+
for (let i = 0; i < cur.length; i++) {
|
|
53
|
+
doDiff(cur[i], pre[i], target, `${path}[${i}]`);
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (curRootType === OBJECT_TYPE &&
|
|
58
|
+
preRootType === curRootType &&
|
|
59
|
+
(root || Object.keys(cur).length >= Object.keys(pre).length)) {
|
|
60
|
+
const keys = Object.keys(cur);
|
|
61
|
+
for (let key of keys) {
|
|
62
|
+
const curVal = cur[key], preVal = pre[key];
|
|
63
|
+
const curType = getType(curVal), preType = getType(preVal);
|
|
64
|
+
if (curVal === preVal)
|
|
65
|
+
continue;
|
|
66
|
+
if (curType === ARRAY_TYPE && preType === curType && curVal.length >= preVal.length) {
|
|
67
|
+
for (let i = 0; i < curVal.length; i++) {
|
|
68
|
+
doDiff(curVal[i], preVal[i], target, `${path ? path + "." : ""}${key}[${i}]`);
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (curType === OBJECT_TYPE && preType === curType && Object.keys(curVal).length >= Object.keys(preVal).length) {
|
|
73
|
+
for (let sKey in curVal) {
|
|
74
|
+
doDiff(curVal[sKey], preVal[sKey], target, `${path ? path + "." : ""}${key}.${sKey}`);
|
|
75
|
+
}
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
target[`${path ? path + "." : ""}${key}`] = curVal;
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
target[path] = cur;
|
|
83
|
+
};
|
|
84
|
+
function diff(data, prevData) {
|
|
85
|
+
const target = {};
|
|
86
|
+
initPath(data);
|
|
87
|
+
initData(data, prevData, true);
|
|
88
|
+
doDiff(data, prevData, target, "", true);
|
|
89
|
+
return target;
|
|
90
|
+
}
|
|
91
|
+
exports.default = diff;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const diff_1 = require("./diff");
|
|
4
|
+
const hook_1 = require("../hook");
|
|
5
|
+
const promixify = (miniapi) => {
|
|
6
|
+
return (options, ...params) => {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
miniapi(Object.assign({}, options, { success: resolve, fail: reject }), ...params);
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
// const api = (miniapi, options, ...params) => {
|
|
13
|
+
// return hook.run(new Promise((resolve, reject) => {
|
|
14
|
+
// miniapi(Object.assign({}, options || {}, { success: resolve, fail: reject }), ...params)
|
|
15
|
+
// }))
|
|
16
|
+
// }
|
|
17
|
+
const api = (miniapi, options = null, ...params) => {
|
|
18
|
+
return hook_1.default.run(promixify(miniapi)(options, ...params));
|
|
19
|
+
};
|
|
20
|
+
exports.default = { diff: diff_1.default, promixify, api };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function hasOwnProperty(obj, prop) {
|
|
4
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
5
|
+
}
|
|
6
|
+
const decode = function (qs, { sep = "&", eq = "=", max = 1000, multiple = false } = {}) {
|
|
7
|
+
sep = sep || '&';
|
|
8
|
+
eq = eq || '=';
|
|
9
|
+
const obj = {};
|
|
10
|
+
if (typeof qs !== 'string' || qs.length === 0) {
|
|
11
|
+
return obj;
|
|
12
|
+
}
|
|
13
|
+
const regexp = /\+/g;
|
|
14
|
+
qs = qs.split(sep);
|
|
15
|
+
const maxKeys = max || 1000;
|
|
16
|
+
let len = qs.length;
|
|
17
|
+
// maxKeys <= 0 means that we should not limit keys count
|
|
18
|
+
if (maxKeys > 0 && len > maxKeys) {
|
|
19
|
+
len = maxKeys;
|
|
20
|
+
}
|
|
21
|
+
for (let i = 0; i < len; ++i) {
|
|
22
|
+
let x = qs[i].replace(regexp, '%20'), idx = x.indexOf(eq), kstr, vstr, k, v;
|
|
23
|
+
if (idx >= 0) {
|
|
24
|
+
kstr = x.substr(0, idx);
|
|
25
|
+
vstr = x.substr(idx + 1);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
kstr = x;
|
|
29
|
+
vstr = '';
|
|
30
|
+
}
|
|
31
|
+
k = decodeURIComponent(kstr);
|
|
32
|
+
v = decodeURIComponent(vstr);
|
|
33
|
+
if (!hasOwnProperty(obj, k) || !multiple) {
|
|
34
|
+
obj[k] = v;
|
|
35
|
+
}
|
|
36
|
+
else if (Array.isArray(obj[k])) {
|
|
37
|
+
obj[k].push(v);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
obj[k] = [obj[k], v];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return obj;
|
|
44
|
+
};
|
|
45
|
+
exports.default = decode;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const stringifyPrimitive = function (v) {
|
|
4
|
+
switch (typeof v) {
|
|
5
|
+
case 'string':
|
|
6
|
+
return v;
|
|
7
|
+
case 'boolean':
|
|
8
|
+
return v ? 'true' : 'false';
|
|
9
|
+
case 'number':
|
|
10
|
+
return isFinite(v) ? v : '';
|
|
11
|
+
default:
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const encode = function (obj, { sep = "&", eq = "=", name = null, multiple = false } = {}) {
|
|
16
|
+
sep = sep || '&';
|
|
17
|
+
eq = eq || '=';
|
|
18
|
+
if (obj === null) {
|
|
19
|
+
obj = undefined;
|
|
20
|
+
}
|
|
21
|
+
if (typeof obj === 'object') {
|
|
22
|
+
return Object.keys(obj).map(function (k) {
|
|
23
|
+
const ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
|
|
24
|
+
if (multiple && Array.isArray(obj[k])) {
|
|
25
|
+
return obj[k].map(function (v) {
|
|
26
|
+
return ks + encodeURIComponent(stringifyPrimitive(v));
|
|
27
|
+
}).join(sep);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
|
|
31
|
+
}
|
|
32
|
+
}).filter(Boolean).join(sep);
|
|
33
|
+
}
|
|
34
|
+
if (!name)
|
|
35
|
+
return '';
|
|
36
|
+
return encodeURIComponent(stringifyPrimitive(name)) + eq + encodeURIComponent(stringifyPrimitive(obj));
|
|
37
|
+
};
|
|
38
|
+
exports.default = encode;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const decode_1 = require("./decode");
|
|
4
|
+
const encode_1 = require("./encode");
|
|
5
|
+
exports.default = { parse: decode_1.default, decode: decode_1.default, stringify: encode_1.default, encode: encode_1.default };
|
package/bin/types/index.d.ts
CHANGED
|
@@ -64,6 +64,17 @@ declare const _default: {
|
|
|
64
64
|
take: (list: any[], count: number, skip?: number) => any[];
|
|
65
65
|
distinct: (list: any[]) => any[];
|
|
66
66
|
};
|
|
67
|
+
mini: {
|
|
68
|
+
diff: typeof import("./modules/mini/diff").default;
|
|
69
|
+
promixify: (wxapi: any) => (options: any, ...params: any[]) => Promise<any[]>;
|
|
70
|
+
api: (miniapi: any, options: any, ...params: any[]) => Promise<any[]>;
|
|
71
|
+
};
|
|
72
|
+
url: {
|
|
73
|
+
parse: (qs: any, sep: any, eq: any, options: any) => {};
|
|
74
|
+
decode: (qs: any, sep: any, eq: any, options: any) => {};
|
|
75
|
+
stringify: (obj: any, sep: any, eq: any, name: any) => string;
|
|
76
|
+
encode: (obj: any, sep: any, eq: any, name: any) => string;
|
|
77
|
+
};
|
|
67
78
|
DEvent: typeof DEvent;
|
|
68
79
|
store: typeof store;
|
|
69
80
|
storeRef: (source: import("./typings").IDStore) => store & import("./typings").IDStore;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function diff(data: any, prevData: any): {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
parse: (qs: any, sep: any, eq: any, options: any) => {};
|
|
3
|
+
decode: (qs: any, sep: any, eq: any, options: any) => {};
|
|
4
|
+
stringify: (obj: any, sep: any, eq: any, name: any) => string;
|
|
5
|
+
encode: (obj: any, sep: any, eq: any, name: any) => string;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|