ddan-js 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/bin/ddan-js.esm.js +1 -239
- package/bin/ddan-js.js +1 -253
- package/bin/lib/class/event.js +79 -0
- package/bin/lib/common/_Symbol.js +5 -0
- package/bin/lib/common/_freeGlobal.js +5 -0
- package/bin/lib/common/_object.js +40 -0
- package/bin/lib/common/_root.js +8 -0
- package/bin/lib/index.js +13 -10
- package/bin/lib/modules/gbk.js +6 -8
- package/bin/lib/modules/hook/debounce.js +107 -0
- package/bin/lib/modules/hook/index.js +25 -0
- package/bin/lib/modules/hook/throttle.js +24 -0
- package/bin/lib/modules/math/index.js +27 -0
- package/bin/lib/modules/time.js +17 -13
- package/bin/lib/modules/util/includes.js +96 -0
- package/bin/lib/modules/util/index.js +17 -0
- package/bin/lib/modules/util/is.js +78 -0
- package/bin/lib/modules/util/to.js +47 -0
- package/bin/types/class/event.d.ts +10 -0
- package/bin/types/common/_Symbol.d.ts +2 -0
- package/bin/types/common/_freeGlobal.d.ts +3 -0
- package/bin/types/common/_object.d.ts +10 -0
- package/bin/types/common/_root.d.ts +3 -0
- package/bin/types/index.d.ts +60 -5
- package/bin/types/modules/gbk.d.ts +7 -2
- package/bin/types/modules/hook/debounce.d.ts +12 -0
- package/bin/types/modules/hook/index.d.ts +12 -0
- package/bin/types/modules/hook/throttle.d.ts +8 -0
- package/bin/types/modules/math/index.d.ts +24 -0
- package/bin/types/modules/time.d.ts +9 -14
- package/bin/types/modules/util/includes.d.ts +2 -0
- package/bin/types/modules/util/index.d.ts +23 -0
- package/bin/types/modules/util/is.d.ts +28 -0
- package/bin/types/modules/util/to.d.ts +9 -0
- package/package.json +3 -2
- package/bin/lib/common/is.js +0 -32
- package/bin/lib/common/util.js +0 -23
- package/bin/lib/modules/hook.js +0 -61
- package/bin/lib/modules/math.js +0 -29
- package/bin/types/common/is.d.ts +0 -13
- package/bin/types/common/util.d.ts +0 -5
- package/bin/types/modules/hook.d.ts +0 -10
- package/bin/types/modules/math.d.ts +0 -20
package/README.md
CHANGED
package/bin/ddan-js.esm.js
CHANGED
|
@@ -1,239 +1 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
* @param str
|
|
4
|
-
* @returns
|
|
5
|
-
*/
|
|
6
|
-
function gbkLength(str) {
|
|
7
|
-
let len = 0;
|
|
8
|
-
if (!str)
|
|
9
|
-
return 0;
|
|
10
|
-
for (let i = 0; i < str.length; i++) {
|
|
11
|
-
if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
|
|
12
|
-
len += 2;
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
len++;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return len;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 根据gbk字符长度截取内容
|
|
22
|
-
* @param {string} source
|
|
23
|
-
* @param {number} len
|
|
24
|
-
*/
|
|
25
|
-
function gbkCut(source, len) {
|
|
26
|
-
if (!source || len <= 0)
|
|
27
|
-
return "";
|
|
28
|
-
let n = 0;
|
|
29
|
-
let idx = 0;
|
|
30
|
-
for (let i = 0; i < source.length; i++) {
|
|
31
|
-
if (source.charCodeAt(i) > 127 || source.charCodeAt(i) === 94) {
|
|
32
|
-
n += 2;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
n++;
|
|
36
|
-
}
|
|
37
|
-
if (n > len) {
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
idx = i;
|
|
41
|
-
}
|
|
42
|
-
return source.substr(0, idx + 1);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
var gbk = /*#__PURE__*/Object.freeze({
|
|
46
|
-
__proto__: null,
|
|
47
|
-
gbkLength: gbkLength,
|
|
48
|
-
gbkCut: gbkCut
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 是否是今天
|
|
53
|
-
* @param {*} date
|
|
54
|
-
* @returns
|
|
55
|
-
*/
|
|
56
|
-
const isToday = (date) => new Date().toDateString() === new Date(date).toDateString();
|
|
57
|
-
/**
|
|
58
|
-
* 时间格式化
|
|
59
|
-
* @param {string|number|Date} time
|
|
60
|
-
* @param {string} reg "yyyyMMdd hhmmss"
|
|
61
|
-
* @returns
|
|
62
|
-
*/
|
|
63
|
-
const timeFormat = (time, reg) => {
|
|
64
|
-
const date = typeof time === "string" || typeof time === "number" ? new Date(time) : time;
|
|
65
|
-
const map = {};
|
|
66
|
-
map.yyyy = date.getFullYear();
|
|
67
|
-
map.yy = `${map.yyyy}`.substr(2);
|
|
68
|
-
map.M = date.getMonth() + 1;
|
|
69
|
-
map.MM = (map.M < 10 ? "0" : "") + map.M;
|
|
70
|
-
map.d = date.getDate();
|
|
71
|
-
map.dd = (map.d < 10 ? "0" : "") + map.d;
|
|
72
|
-
map.h = date.getHours();
|
|
73
|
-
map.hh = (map.h < 10 ? "0" : "") + map.h;
|
|
74
|
-
map.m = date.getMinutes();
|
|
75
|
-
map.mm = (map.m < 10 ? "0" : "") + map.m;
|
|
76
|
-
map.s = date.getSeconds();
|
|
77
|
-
map.ss = (map.s < 10 ? "0" : "") + map.s;
|
|
78
|
-
map.S = date.getMilliseconds();
|
|
79
|
-
map.SS = (map.S < 10 ? "0" : "") + map.S;
|
|
80
|
-
map.SSS = map.S.toString().padStart(3, 0);
|
|
81
|
-
return reg.replace(/\byyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g, ($1) => map[$1]);
|
|
82
|
-
};
|
|
83
|
-
function parseTime({ year = 0, month = 0, date = 0, hour = 0, minute = 0, second = 0 }) {
|
|
84
|
-
const format = `${year || "yyyy"}/${month || "MM"}/${date || "dd"} ${hour}:${minute}:${second}`;
|
|
85
|
-
return new Date(timeFormat(Date.now(), format)).getTime();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
var time = /*#__PURE__*/Object.freeze({
|
|
89
|
-
__proto__: null,
|
|
90
|
-
isToday: isToday,
|
|
91
|
-
timeFormat: timeFormat,
|
|
92
|
-
parseTime: parseTime
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* 休眠
|
|
97
|
-
* @param {number} time
|
|
98
|
-
* @returns
|
|
99
|
-
*/
|
|
100
|
-
const sleep = (time = 1000) => new Promise((resolve) => {
|
|
101
|
-
setTimeout(resolve, time);
|
|
102
|
-
});
|
|
103
|
-
function run(cb) {
|
|
104
|
-
try {
|
|
105
|
-
if (!cb)
|
|
106
|
-
return null;
|
|
107
|
-
return cb();
|
|
108
|
-
}
|
|
109
|
-
catch (err) {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
const task = (promise) => promise.then((data) => [data, null]).catch((err) => [undefined, err]);
|
|
114
|
-
const debounce = (fn, interval = 300) => {
|
|
115
|
-
let timer;
|
|
116
|
-
const intervalTime = interval || 300;
|
|
117
|
-
return function func(...args) {
|
|
118
|
-
const context = this;
|
|
119
|
-
if (timer)
|
|
120
|
-
clearTimeout(timer);
|
|
121
|
-
timer = setTimeout(() => {
|
|
122
|
-
fn.call(context, ...args);
|
|
123
|
-
}, intervalTime);
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
const throttle = (fn, delay = 300) => {
|
|
127
|
-
let timer;
|
|
128
|
-
const delayTime = delay || 300;
|
|
129
|
-
let lastTime = Date.now();
|
|
130
|
-
return function func(...args) {
|
|
131
|
-
const context = this;
|
|
132
|
-
const curTime = Date.now();
|
|
133
|
-
const remaining = delayTime - (curTime - lastTime);
|
|
134
|
-
if (remaining < 0) {
|
|
135
|
-
timer && clearTimeout(timer);
|
|
136
|
-
timer = null;
|
|
137
|
-
fn.call(context, ...args);
|
|
138
|
-
lastTime = curTime;
|
|
139
|
-
}
|
|
140
|
-
else if (!timer) {
|
|
141
|
-
timer = setTimeout(() => {
|
|
142
|
-
fn.call(context, ...args);
|
|
143
|
-
lastTime = Date.now();
|
|
144
|
-
}, delayTime);
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
var hook = /*#__PURE__*/Object.freeze({
|
|
150
|
-
__proto__: null,
|
|
151
|
-
sleep: sleep,
|
|
152
|
-
run: run,
|
|
153
|
-
task: task,
|
|
154
|
-
debounce: debounce,
|
|
155
|
-
throttle: throttle
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
class math {
|
|
159
|
-
/**
|
|
160
|
-
* 随机取值[0, max)
|
|
161
|
-
* @param max 最大值
|
|
162
|
-
*/
|
|
163
|
-
static random(max) {
|
|
164
|
-
return Math.floor(Math.random() * max);
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* 范围随机取值[min, max]
|
|
168
|
-
* @param min 最小值
|
|
169
|
-
* @param max 最大值
|
|
170
|
-
*/
|
|
171
|
-
static randomRange(min, max) {
|
|
172
|
-
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* 插值
|
|
176
|
-
* @param start
|
|
177
|
-
* @param end
|
|
178
|
-
* @param t
|
|
179
|
-
*/
|
|
180
|
-
static lerp(start, end, t) {
|
|
181
|
-
return start * (1 - t) + end * t;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const { toString } = Object.prototype;
|
|
186
|
-
const util = {
|
|
187
|
-
getTag(value) {
|
|
188
|
-
if (value == null) {
|
|
189
|
-
return value === undefined ? "[object Undefined]" : "[object Null]";
|
|
190
|
-
}
|
|
191
|
-
return toString.call(value);
|
|
192
|
-
},
|
|
193
|
-
getType(value) {
|
|
194
|
-
let str = "";
|
|
195
|
-
if (value == null) {
|
|
196
|
-
str = value === undefined ? "[object Undefined]" : "[object Null]";
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
str = toString.call(value);
|
|
200
|
-
}
|
|
201
|
-
const mat = str.match(/\w+/g) || ["object", "Undefined"];
|
|
202
|
-
return mat[1] || "";
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* 判断是否数字
|
|
208
|
-
* @param value
|
|
209
|
-
* @returns
|
|
210
|
-
*/
|
|
211
|
-
function isNumber(value) {
|
|
212
|
-
return util.getTag(value) === "[object Number]";
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* 判断是否是字符串
|
|
216
|
-
* @param value
|
|
217
|
-
* @returns
|
|
218
|
-
*/
|
|
219
|
-
function isString(value) {
|
|
220
|
-
return util.getTag(value) === "[object String]";
|
|
221
|
-
}
|
|
222
|
-
function isChinese(content) {
|
|
223
|
-
if (!content)
|
|
224
|
-
return false;
|
|
225
|
-
const reg = /^[\u4E00-\u9FA5]+$/;
|
|
226
|
-
if (!reg.test(content)) {
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
return true;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
var is = /*#__PURE__*/Object.freeze({
|
|
233
|
-
__proto__: null,
|
|
234
|
-
isNumber: isNumber,
|
|
235
|
-
isString: isString,
|
|
236
|
-
isChinese: isChinese
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
export { gbk, hook, is, math, time };
|
|
1
|
+
var t={gbkLength:function(t){var n=0;if(!t)return 0;for(var r=0;r<t.length;r++)t.charCodeAt(r)>127||94===t.charCodeAt(r)?n+=2:n++;return n},gbkCut:function(t,n){if(!t||n<=0)return"";for(var r=0,e=0,o=0;o<t.length&&(t.charCodeAt(o)>127||94===t.charCodeAt(o)?r+=2:r++,!(r>n));o++)e=o;return t.substr(0,e+1)}},n="object"==typeof global&&global&&global.Object===Object&&global,r="object"==typeof self&&self&&self.Object===Object&&self,e=n||r||Function("return this")(),o=function(t,n){void 0===n&&(n="yyyy-MM-dd hh:mm:ss");var r="string"==typeof t||"number"==typeof t?new Date(t):t,e={};return e.yyyy=r.getFullYear(),e.yy="".concat(e.yyyy).substr(2),e.M=r.getMonth()+1,e.MM=(e.M<10?"0":"")+e.M,e.d=r.getDate(),e.dd=(e.d<10?"0":"")+e.d,e.h=r.getHours(),e.hh=(e.h<10?"0":"")+e.h,e.m=r.getMinutes(),e.mm=(e.m<10?"0":"")+e.m,e.s=r.getSeconds(),e.ss=(e.s<10?"0":"")+e.s,e.S=r.getMilliseconds(),e.SS=(e.S<10?"0":"")+e.S,e.SSS=e.S.toString().padStart(3,0),n.replace(/\byyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g,(function(t){return e[t]}))};var i={now:function(){return e.Date.now()},isToday:function(t){return(new Date).toDateString()===new Date(t).toDateString()},timeFormat:o,parseTime:function(t){var n=t.year,r=void 0===n?0:n,e=t.month,i=void 0===e?0:e,u=t.date,a=void 0===u?0:u,c=t.hour,f=void 0===c?0:c,s=t.minute,l=void 0===s?0:s,y=t.second,p=void 0===y?0:y,h="".concat(r||"yyyy","/").concat(i||"MM","/").concat(a||"dd"," ").concat(f,":").concat(l,":").concat(p);return new Date(o(Date.now(),h)).getTime()}},u=e.Symbol,a=Object.prototype,c=a.toString,f=a.hasOwnProperty,s=a.propertyIsEnumerable,l=u?u.toStringTag:void 0;function y(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":l&&l in Object(t)?function(t){var n=f.call(t,l),r=t[l],e=!1;try{t[l]=void 0,e=!0}catch(t){}var o=c.call(t);return e&&(n?t[l]=r:delete t[l]),o}(t):c.call(t)}var p={getTag:y,getType:function(t){return(y(t).match(/\w+/g)||["object","Undefined"])[1]||""},toString:c,hasOwnProperty:f,propertyIsEnumerable:s},h="[object Function]",v="[object GeneratorFunction]",g=9007199254740991,d=/^(?:0|[1-9]\d*)$/;function m(t){var n=typeof t;return null!=t&&("object"==n||"function"==n)}function b(t){return null!=t&&"object"==typeof t}var S=Array.isArray;function j(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=g}(t.length)&&!w(t)}function O(t){return b(t)&&j(t)}function w(t){var n=m(t)?p.getTag(t):"";return n===h||n===v}var M={isNumber:function(t){return"[object Number]"===p.getTag(t)},isString:function(t){return"string"==typeof t||!S(t)&&b(t)&&"[object String]"==p.getTag(t)},isChinese:function(t){return!!t&&!!/^[\u4E00-\u9FA5]+$/.test(t)},isObject:m,isObjectLike:b,isSymbol:function(t){return"symbol"==typeof t||b(t)&&"[object Symbol]"===p.getTag(t)},isFunction:w,isArray:S,isArrayLikeObject:O,isIndex:function(t,n){return!!(n=null==n?g:n)&&("number"==typeof t||d.test(t))&&t>-1&&t%1==0&&t<n},isArrayLike:j,isPrototype:function(t){var n=t&&t.constructor;return t===("function"==typeof n&&n.prototype||Object.prototype)},isArguments:function(t){return O(t)&&p.hasOwnProperty.call(t,"callee")&&(!p.propertyIsEnumerable.call(t,"callee")||"[object Arguments]"==p.toString.call(t))}},A=NaN,T=/^\s+|\s+$/g,D=/^[-+]0x[0-9a-f]+$/i,x=/^0b[01]+$/i,k=/^0o[0-7]+$/i,E=parseInt,P=1/0,_=17976931348623157e292;function F(t){if("number"==typeof t)return t;if(M.isSymbol(t))return A;if(M.isObject(t)){var n="function"==typeof t.valueOf?t.valueOf():t;t=M.isObject(n)?n+"":n}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(T,"");var r=x.test(t);return r||k.test(t)?E(t.slice(2),r?2:8):D.test(t)?A:+t}function I(t){return t?(t=F(t))===P||t===-P?(t<0?-1:1)*_:t==t?t:0:0===t?t:0}var N={toNumber:F,toFinite:I,toInteger:function(t){var n=I(t),r=n%1;return n==n?r?n-r:n:0}},C="Expected a function",L=Math.max,$=Math.min;function W(t,n,r){void 0===n&&(n=0),void 0===r&&(r={});var e,o,i,u,a,c,f=0,s=!1,l=!1,y=!0;if("function"!=typeof t)throw new TypeError(C);function p(n){var r=e,i=o;return e=o=void 0,f=n,u=t.apply(i,r)}function h(t){var r=t-c;return void 0===c||r>=n||r<0||l&&t-f>=i}function v(){var t=Date.now();if(h(t))return g(t);a=setTimeout(v,function(t){var r=n-(t-c);return l?$(r,i-(t-f)):r}(t))}function g(t){return a=void 0,y&&e?p(t):(e=o=void 0,u)}function d(){var t=Date.now(),r=h(t);if(e=arguments,o=this,c=t,r){if(void 0===a)return function(t){return f=t,a=setTimeout(v,n),s?p(t):u}(c);if(l)return a=setTimeout(v,n),p(c)}return void 0===a&&(a=setTimeout(v,n)),u}return n=N.toNumber(n)||0,M.isObject(r)&&(s=!!r.leading,i=(l="maxWait"in r)?L(N.toNumber(r.maxWait)||0,n):i,y="trailing"in r?!!r.trailing:y),d.cancel=function(){void 0!==a&&clearTimeout(a),f=0,e=c=o=a=void 0},d.flush=function(){return void 0===a?u:g(Date.now())},d}var U={sleep:function(t){return void 0===t&&(t=1e3),new Promise((function(n){setTimeout(n,t)}))},run:function(t){return t.then((function(t){return[null,t]})).catch((function(t){return[t,void 0]}))},debounce:W,throttle:function(t,n,r){void 0===n&&(n=0),void 0===r&&(r={});var e=!1,o=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return M.isObject(r)&&(e=r.leading?!!r.leading:e,o=r.trailing?!!r.trailing:o),W(t,n,{leading:e,maxWait:n,trailing:o})},listStep:function(t,n,r){if(void 0===r&&(r=100),"function"==typeof n&&M.isArray(t)&&!(t.length<=0))for(var e=0;t.length>e;){var o=r+e,i=t.slice(e,o);n&&n(i),e=o}}};var G={random:function(t){return Math.floor(Math.random()*t)},randomRange:function(t,n){return Math.floor(Math.random()*(n-t+1)+t)},lerp:function(t,n,r){return t*(1-r)+n*r}},H=function(){return H=Object.assign||function(t){for(var n,r=1,e=arguments.length;r<e;r++)for(var o in n=arguments[r])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},H.apply(this,arguments)};function R(t){return t!=t}function Y(t,n){return function(t,n){for(var r=-1,e=t?t.length:0,o=Array(e);++r<e;)o[r]=n(t[r],r,t);return o}(n,(function(n){return t[n]}))}var q,z,B=(q=Object.keys,z=Object,function(t){return q(z(t))}),J=Math.max;function K(t,n){var r=M.isArray(t)||M.isArguments(t)?function(t,n){for(var r=-1,e=Array(t);++r<t;)e[r]=n(r);return e}(t.length,String):[],e=r.length,o=!!e;for(var i in t)!n&&!p.hasOwnProperty.call(t,i)||o&&("length"==i||M.isIndex(i,e))||r.push(i);return r}var Q=H(H(H({},M),p),{includes:function(t,n,r,e){var o;t=M.isArrayLike(t)?t:(o=t)?Y(o,function(t){return M.isArrayLike(t)?K(t):function(t){if(!M.isPrototype(t))return B(t);var n=[];for(var r in Object(t))p.hasOwnProperty.call(t,r)&&"constructor"!=r&&n.push(r);return n}(t)}(o)):[],r=r&&!e?N.toInteger(r):0;var i=t.length;return r<0&&(r=J(i+r,0)),M.isString(t)?r<=i&&t.indexOf(n,r)>-1:!!i&&function(t,n,r){if(n!=n)return function(t,n,r,e){for(var o=t.length,i=r+(e?1:-1);e?i--:++i<o;)if(n(t[i],i,t))return i;return-1}(t,R,r);for(var e=r-1,o=t.length;++e<o;)if(t[e]===n)return e;return-1}(t,n,r)>-1}}),V=function(){function t(){this._map=new Map}return t.prototype.clear=function(){return this._map.clear(),this},t.prototype.on=function(t,n){if(!n)return this;var r=this._map.get(t);return r||(r=new Set,this._map.set(t,r)),r.add(n),this},t.prototype.emit=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var e=this._map.get(t);if(!e)return this;var o=function(t,n,r){if(r||2===arguments.length)for(var e,o=0,i=n.length;o<i;o++)!e&&o in n||(e||(e=Array.prototype.slice.call(n,0,o)),e[o]=n[o]);return t.concat(e||Array.prototype.slice.call(n))}([],e,!0);return o.forEach((function(t){return t.apply(void 0,n)})),this},t.prototype.off=function(t,n){if(void 0===t&&(t=""),!t)return this._map.clear(),this;if(!n)return this._map.delete(t.toString()),this;var r=this._map.get(t);return r?(r.delete(n),this):this},t.prototype.once=function(t,n){var r=this,e=function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n.apply(void 0,o),r.off(t,e)};return this.on(t,e),this},t.prototype.has=function(t){return this._map.has(t)},t}(),X={gbk:t,time:i,hook:U,math:G,util:Q,DdEvent:V};export{V as DdEvent,X as default,t as gbk,U as hook,G as math,i as time,Q as util};
|
package/bin/ddan-js.js
CHANGED
|
@@ -1,253 +1 @@
|
|
|
1
|
-
(function (global,
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.DdanJs = {}));
|
|
5
|
-
})(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param str
|
|
10
|
-
* @returns
|
|
11
|
-
*/
|
|
12
|
-
function gbkLength(str) {
|
|
13
|
-
let len = 0;
|
|
14
|
-
if (!str)
|
|
15
|
-
return 0;
|
|
16
|
-
for (let i = 0; i < str.length; i++) {
|
|
17
|
-
if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
|
|
18
|
-
len += 2;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
len++;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return len;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* 根据gbk字符长度截取内容
|
|
28
|
-
* @param {string} source
|
|
29
|
-
* @param {number} len
|
|
30
|
-
*/
|
|
31
|
-
function gbkCut(source, len) {
|
|
32
|
-
if (!source || len <= 0)
|
|
33
|
-
return "";
|
|
34
|
-
let n = 0;
|
|
35
|
-
let idx = 0;
|
|
36
|
-
for (let i = 0; i < source.length; i++) {
|
|
37
|
-
if (source.charCodeAt(i) > 127 || source.charCodeAt(i) === 94) {
|
|
38
|
-
n += 2;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
n++;
|
|
42
|
-
}
|
|
43
|
-
if (n > len) {
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
idx = i;
|
|
47
|
-
}
|
|
48
|
-
return source.substr(0, idx + 1);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var gbk = /*#__PURE__*/Object.freeze({
|
|
52
|
-
__proto__: null,
|
|
53
|
-
gbkLength: gbkLength,
|
|
54
|
-
gbkCut: gbkCut
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 是否是今天
|
|
59
|
-
* @param {*} date
|
|
60
|
-
* @returns
|
|
61
|
-
*/
|
|
62
|
-
const isToday = (date) => new Date().toDateString() === new Date(date).toDateString();
|
|
63
|
-
/**
|
|
64
|
-
* 时间格式化
|
|
65
|
-
* @param {string|number|Date} time
|
|
66
|
-
* @param {string} reg "yyyyMMdd hhmmss"
|
|
67
|
-
* @returns
|
|
68
|
-
*/
|
|
69
|
-
const timeFormat = (time, reg) => {
|
|
70
|
-
const date = typeof time === "string" || typeof time === "number" ? new Date(time) : time;
|
|
71
|
-
const map = {};
|
|
72
|
-
map.yyyy = date.getFullYear();
|
|
73
|
-
map.yy = `${map.yyyy}`.substr(2);
|
|
74
|
-
map.M = date.getMonth() + 1;
|
|
75
|
-
map.MM = (map.M < 10 ? "0" : "") + map.M;
|
|
76
|
-
map.d = date.getDate();
|
|
77
|
-
map.dd = (map.d < 10 ? "0" : "") + map.d;
|
|
78
|
-
map.h = date.getHours();
|
|
79
|
-
map.hh = (map.h < 10 ? "0" : "") + map.h;
|
|
80
|
-
map.m = date.getMinutes();
|
|
81
|
-
map.mm = (map.m < 10 ? "0" : "") + map.m;
|
|
82
|
-
map.s = date.getSeconds();
|
|
83
|
-
map.ss = (map.s < 10 ? "0" : "") + map.s;
|
|
84
|
-
map.S = date.getMilliseconds();
|
|
85
|
-
map.SS = (map.S < 10 ? "0" : "") + map.S;
|
|
86
|
-
map.SSS = map.S.toString().padStart(3, 0);
|
|
87
|
-
return reg.replace(/\byyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g, ($1) => map[$1]);
|
|
88
|
-
};
|
|
89
|
-
function parseTime({ year = 0, month = 0, date = 0, hour = 0, minute = 0, second = 0 }) {
|
|
90
|
-
const format = `${year || "yyyy"}/${month || "MM"}/${date || "dd"} ${hour}:${minute}:${second}`;
|
|
91
|
-
return new Date(timeFormat(Date.now(), format)).getTime();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
var time = /*#__PURE__*/Object.freeze({
|
|
95
|
-
__proto__: null,
|
|
96
|
-
isToday: isToday,
|
|
97
|
-
timeFormat: timeFormat,
|
|
98
|
-
parseTime: parseTime
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* 休眠
|
|
103
|
-
* @param {number} time
|
|
104
|
-
* @returns
|
|
105
|
-
*/
|
|
106
|
-
const sleep = (time = 1000) => new Promise((resolve) => {
|
|
107
|
-
setTimeout(resolve, time);
|
|
108
|
-
});
|
|
109
|
-
function run(cb) {
|
|
110
|
-
try {
|
|
111
|
-
if (!cb)
|
|
112
|
-
return null;
|
|
113
|
-
return cb();
|
|
114
|
-
}
|
|
115
|
-
catch (err) {
|
|
116
|
-
return undefined;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const task = (promise) => promise.then((data) => [data, null]).catch((err) => [undefined, err]);
|
|
120
|
-
const debounce = (fn, interval = 300) => {
|
|
121
|
-
let timer;
|
|
122
|
-
const intervalTime = interval || 300;
|
|
123
|
-
return function func(...args) {
|
|
124
|
-
const context = this;
|
|
125
|
-
if (timer)
|
|
126
|
-
clearTimeout(timer);
|
|
127
|
-
timer = setTimeout(() => {
|
|
128
|
-
fn.call(context, ...args);
|
|
129
|
-
}, intervalTime);
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
const throttle = (fn, delay = 300) => {
|
|
133
|
-
let timer;
|
|
134
|
-
const delayTime = delay || 300;
|
|
135
|
-
let lastTime = Date.now();
|
|
136
|
-
return function func(...args) {
|
|
137
|
-
const context = this;
|
|
138
|
-
const curTime = Date.now();
|
|
139
|
-
const remaining = delayTime - (curTime - lastTime);
|
|
140
|
-
if (remaining < 0) {
|
|
141
|
-
timer && clearTimeout(timer);
|
|
142
|
-
timer = null;
|
|
143
|
-
fn.call(context, ...args);
|
|
144
|
-
lastTime = curTime;
|
|
145
|
-
}
|
|
146
|
-
else if (!timer) {
|
|
147
|
-
timer = setTimeout(() => {
|
|
148
|
-
fn.call(context, ...args);
|
|
149
|
-
lastTime = Date.now();
|
|
150
|
-
}, delayTime);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
var hook = /*#__PURE__*/Object.freeze({
|
|
156
|
-
__proto__: null,
|
|
157
|
-
sleep: sleep,
|
|
158
|
-
run: run,
|
|
159
|
-
task: task,
|
|
160
|
-
debounce: debounce,
|
|
161
|
-
throttle: throttle
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
class math {
|
|
165
|
-
/**
|
|
166
|
-
* 随机取值[0, max)
|
|
167
|
-
* @param max 最大值
|
|
168
|
-
*/
|
|
169
|
-
static random(max) {
|
|
170
|
-
return Math.floor(Math.random() * max);
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* 范围随机取值[min, max]
|
|
174
|
-
* @param min 最小值
|
|
175
|
-
* @param max 最大值
|
|
176
|
-
*/
|
|
177
|
-
static randomRange(min, max) {
|
|
178
|
-
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* 插值
|
|
182
|
-
* @param start
|
|
183
|
-
* @param end
|
|
184
|
-
* @param t
|
|
185
|
-
*/
|
|
186
|
-
static lerp(start, end, t) {
|
|
187
|
-
return start * (1 - t) + end * t;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const { toString } = Object.prototype;
|
|
192
|
-
const util = {
|
|
193
|
-
getTag(value) {
|
|
194
|
-
if (value == null) {
|
|
195
|
-
return value === undefined ? "[object Undefined]" : "[object Null]";
|
|
196
|
-
}
|
|
197
|
-
return toString.call(value);
|
|
198
|
-
},
|
|
199
|
-
getType(value) {
|
|
200
|
-
let str = "";
|
|
201
|
-
if (value == null) {
|
|
202
|
-
str = value === undefined ? "[object Undefined]" : "[object Null]";
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
str = toString.call(value);
|
|
206
|
-
}
|
|
207
|
-
const mat = str.match(/\w+/g) || ["object", "Undefined"];
|
|
208
|
-
return mat[1] || "";
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* 判断是否数字
|
|
214
|
-
* @param value
|
|
215
|
-
* @returns
|
|
216
|
-
*/
|
|
217
|
-
function isNumber(value) {
|
|
218
|
-
return util.getTag(value) === "[object Number]";
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* 判断是否是字符串
|
|
222
|
-
* @param value
|
|
223
|
-
* @returns
|
|
224
|
-
*/
|
|
225
|
-
function isString(value) {
|
|
226
|
-
return util.getTag(value) === "[object String]";
|
|
227
|
-
}
|
|
228
|
-
function isChinese(content) {
|
|
229
|
-
if (!content)
|
|
230
|
-
return false;
|
|
231
|
-
const reg = /^[\u4E00-\u9FA5]+$/;
|
|
232
|
-
if (!reg.test(content)) {
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
return true;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
var is = /*#__PURE__*/Object.freeze({
|
|
239
|
-
__proto__: null,
|
|
240
|
-
isNumber: isNumber,
|
|
241
|
-
isString: isString,
|
|
242
|
-
isChinese: isChinese
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
exports.gbk = gbk;
|
|
246
|
-
exports.hook = hook;
|
|
247
|
-
exports.is = is;
|
|
248
|
-
exports.math = math;
|
|
249
|
-
exports.time = time;
|
|
250
|
-
|
|
251
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
252
|
-
|
|
253
|
-
}));
|
|
1
|
+
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).DdanJs={})}(this,(function(t){"use strict";var n={gbkLength:function(t){var n=0;if(!t)return 0;for(var r=0;r<t.length;r++)t.charCodeAt(r)>127||94===t.charCodeAt(r)?n+=2:n++;return n},gbkCut:function(t,n){if(!t||n<=0)return"";for(var r=0,e=0,o=0;o<t.length&&(t.charCodeAt(o)>127||94===t.charCodeAt(o)?r+=2:r++,!(r>n));o++)e=o;return t.substr(0,e+1)}},r="object"==typeof global&&global&&global.Object===Object&&global,e="object"==typeof self&&self&&self.Object===Object&&self,o=r||e||Function("return this")(),i=function(t,n){void 0===n&&(n="yyyy-MM-dd hh:mm:ss");var r="string"==typeof t||"number"==typeof t?new Date(t):t,e={};return e.yyyy=r.getFullYear(),e.yy="".concat(e.yyyy).substr(2),e.M=r.getMonth()+1,e.MM=(e.M<10?"0":"")+e.M,e.d=r.getDate(),e.dd=(e.d<10?"0":"")+e.d,e.h=r.getHours(),e.hh=(e.h<10?"0":"")+e.h,e.m=r.getMinutes(),e.mm=(e.m<10?"0":"")+e.m,e.s=r.getSeconds(),e.ss=(e.s<10?"0":"")+e.s,e.S=r.getMilliseconds(),e.SS=(e.S<10?"0":"")+e.S,e.SSS=e.S.toString().padStart(3,0),n.replace(/\byyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g,(function(t){return e[t]}))};var u={now:function(){return o.Date.now()},isToday:function(t){return(new Date).toDateString()===new Date(t).toDateString()},timeFormat:i,parseTime:function(t){var n=t.year,r=void 0===n?0:n,e=t.month,o=void 0===e?0:e,u=t.date,a=void 0===u?0:u,c=t.hour,f=void 0===c?0:c,s=t.minute,l=void 0===s?0:s,y=t.second,p=void 0===y?0:y,h="".concat(r||"yyyy","/").concat(o||"MM","/").concat(a||"dd"," ").concat(f,":").concat(l,":").concat(p);return new Date(i(Date.now(),h)).getTime()}},a=o.Symbol,c=Object.prototype,f=c.toString,s=c.hasOwnProperty,l=c.propertyIsEnumerable,y=a?a.toStringTag:void 0;function p(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":y&&y in Object(t)?function(t){var n=s.call(t,y),r=t[y],e=!1;try{t[y]=void 0,e=!0}catch(t){}var o=f.call(t);return e&&(n?t[y]=r:delete t[y]),o}(t):f.call(t)}var h={getTag:p,getType:function(t){return(p(t).match(/\w+/g)||["object","Undefined"])[1]||""},toString:f,hasOwnProperty:s,propertyIsEnumerable:l},d="[object Function]",v="[object GeneratorFunction]",g=9007199254740991,m=/^(?:0|[1-9]\d*)$/;function b(t){var n=typeof t;return null!=t&&("object"==n||"function"==n)}function S(t){return null!=t&&"object"==typeof t}var j=Array.isArray;function O(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=g}(t.length)&&!M(t)}function w(t){return S(t)&&O(t)}function M(t){var n=b(t)?h.getTag(t):"";return n===d||n===v}var A={isNumber:function(t){return"[object Number]"===h.getTag(t)},isString:function(t){return"string"==typeof t||!j(t)&&S(t)&&"[object String]"==h.getTag(t)},isChinese:function(t){return!!t&&!!/^[\u4E00-\u9FA5]+$/.test(t)},isObject:b,isObjectLike:S,isSymbol:function(t){return"symbol"==typeof t||S(t)&&"[object Symbol]"===h.getTag(t)},isFunction:M,isArray:j,isArrayLikeObject:w,isIndex:function(t,n){return!!(n=null==n?g:n)&&("number"==typeof t||m.test(t))&&t>-1&&t%1==0&&t<n},isArrayLike:O,isPrototype:function(t){var n=t&&t.constructor;return t===("function"==typeof n&&n.prototype||Object.prototype)},isArguments:function(t){return w(t)&&h.hasOwnProperty.call(t,"callee")&&(!h.propertyIsEnumerable.call(t,"callee")||"[object Arguments]"==h.toString.call(t))}},T=NaN,D=/^\s+|\s+$/g,x=/^[-+]0x[0-9a-f]+$/i,k=/^0b[01]+$/i,E=/^0o[0-7]+$/i,_=parseInt,P=1/0,F=17976931348623157e292;function I(t){if("number"==typeof t)return t;if(A.isSymbol(t))return T;if(A.isObject(t)){var n="function"==typeof t.valueOf?t.valueOf():t;t=A.isObject(n)?n+"":n}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(D,"");var r=k.test(t);return r||E.test(t)?_(t.slice(2),r?2:8):x.test(t)?T:+t}function N(t){return t?(t=I(t))===P||t===-P?(t<0?-1:1)*F:t==t?t:0:0===t?t:0}var C={toNumber:I,toFinite:N,toInteger:function(t){var n=N(t),r=n%1;return n==n?r?n-r:n:0}},L="Expected a function",$=Math.max,W=Math.min;function U(t,n,r){void 0===n&&(n=0),void 0===r&&(r={});var e,o,i,u,a,c,f=0,s=!1,l=!1,y=!0;if("function"!=typeof t)throw new TypeError(L);function p(n){var r=e,i=o;return e=o=void 0,f=n,u=t.apply(i,r)}function h(t){var r=t-c;return void 0===c||r>=n||r<0||l&&t-f>=i}function d(){var t=Date.now();if(h(t))return v(t);a=setTimeout(d,function(t){var r=n-(t-c);return l?W(r,i-(t-f)):r}(t))}function v(t){return a=void 0,y&&e?p(t):(e=o=void 0,u)}function g(){var t=Date.now(),r=h(t);if(e=arguments,o=this,c=t,r){if(void 0===a)return function(t){return f=t,a=setTimeout(d,n),s?p(t):u}(c);if(l)return a=setTimeout(d,n),p(c)}return void 0===a&&(a=setTimeout(d,n)),u}return n=C.toNumber(n)||0,A.isObject(r)&&(s=!!r.leading,i=(l="maxWait"in r)?$(C.toNumber(r.maxWait)||0,n):i,y="trailing"in r?!!r.trailing:y),g.cancel=function(){void 0!==a&&clearTimeout(a),f=0,e=c=o=a=void 0},g.flush=function(){return void 0===a?u:v(Date.now())},g}var G={sleep:function(t){return void 0===t&&(t=1e3),new Promise((function(n){setTimeout(n,t)}))},run:function(t){return t.then((function(t){return[null,t]})).catch((function(t){return[t,void 0]}))},debounce:U,throttle:function(t,n,r){void 0===n&&(n=0),void 0===r&&(r={});var e=!1,o=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return A.isObject(r)&&(e=r.leading?!!r.leading:e,o=r.trailing?!!r.trailing:o),U(t,n,{leading:e,maxWait:n,trailing:o})},listStep:function(t,n,r){if(void 0===r&&(r=100),"function"==typeof n&&A.isArray(t)&&!(t.length<=0))for(var e=0;t.length>e;){var o=r+e,i=t.slice(e,o);n&&n(i),e=o}}};var H={random:function(t){return Math.floor(Math.random()*t)},randomRange:function(t,n){return Math.floor(Math.random()*(n-t+1)+t)},lerp:function(t,n,r){return t*(1-r)+n*r}},J=function(){return J=Object.assign||function(t){for(var n,r=1,e=arguments.length;r<e;r++)for(var o in n=arguments[r])Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o]);return t},J.apply(this,arguments)};function R(t){return t!=t}function Y(t,n){return function(t,n){for(var r=-1,e=t?t.length:0,o=Array(e);++r<e;)o[r]=n(t[r],r,t);return o}(n,(function(n){return t[n]}))}var q,z,B=(q=Object.keys,z=Object,function(t){return q(z(t))}),K=Math.max;function Q(t,n){var r=A.isArray(t)||A.isArguments(t)?function(t,n){for(var r=-1,e=Array(t);++r<t;)e[r]=n(r);return e}(t.length,String):[],e=r.length,o=!!e;for(var i in t)!n&&!h.hasOwnProperty.call(t,i)||o&&("length"==i||A.isIndex(i,e))||r.push(i);return r}var V=J(J(J({},A),h),{includes:function(t,n,r,e){var o;t=A.isArrayLike(t)?t:(o=t)?Y(o,function(t){return A.isArrayLike(t)?Q(t):function(t){if(!A.isPrototype(t))return B(t);var n=[];for(var r in Object(t))h.hasOwnProperty.call(t,r)&&"constructor"!=r&&n.push(r);return n}(t)}(o)):[],r=r&&!e?C.toInteger(r):0;var i=t.length;return r<0&&(r=K(i+r,0)),A.isString(t)?r<=i&&t.indexOf(n,r)>-1:!!i&&function(t,n,r){if(n!=n)return function(t,n,r,e){for(var o=t.length,i=r+(e?1:-1);e?i--:++i<o;)if(n(t[i],i,t))return i;return-1}(t,R,r);for(var e=r-1,o=t.length;++e<o;)if(t[e]===n)return e;return-1}(t,n,r)>-1}}),X=function(){function t(){this._map=new Map}return t.prototype.clear=function(){return this._map.clear(),this},t.prototype.on=function(t,n){if(!n)return this;var r=this._map.get(t);return r||(r=new Set,this._map.set(t,r)),r.add(n),this},t.prototype.emit=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var e=this._map.get(t);if(!e)return this;var o=function(t,n,r){if(r||2===arguments.length)for(var e,o=0,i=n.length;o<i;o++)!e&&o in n||(e||(e=Array.prototype.slice.call(n,0,o)),e[o]=n[o]);return t.concat(e||Array.prototype.slice.call(n))}([],e,!0);return o.forEach((function(t){return t.apply(void 0,n)})),this},t.prototype.off=function(t,n){if(void 0===t&&(t=""),!t)return this._map.clear(),this;if(!n)return this._map.delete(t.toString()),this;var r=this._map.get(t);return r?(r.delete(n),this):this},t.prototype.once=function(t,n){var r=this,e=function(){for(var o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];n.apply(void 0,o),r.off(t,e)};return this.on(t,e),this},t.prototype.has=function(t){return this._map.has(t)},t}(),Z={gbk:n,time:u,hook:G,math:H,util:V,DdEvent:X};t.DdEvent=X,t.default=Z,t.gbk=n,t.hook=G,t.math=H,t.time=u,t.util=V,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
var DdEvent = /** @class */ (function () {
|
|
13
|
+
function DdEvent() {
|
|
14
|
+
this._map = new Map();
|
|
15
|
+
}
|
|
16
|
+
DdEvent.prototype.clear = function () {
|
|
17
|
+
this._map.clear();
|
|
18
|
+
return this;
|
|
19
|
+
};
|
|
20
|
+
DdEvent.prototype.on = function (name, handler) {
|
|
21
|
+
if (!handler)
|
|
22
|
+
return this;
|
|
23
|
+
var handlers = this._map.get(name);
|
|
24
|
+
if (!handlers) {
|
|
25
|
+
handlers = new Set();
|
|
26
|
+
this._map.set(name, handlers);
|
|
27
|
+
}
|
|
28
|
+
handlers.add(handler);
|
|
29
|
+
return this;
|
|
30
|
+
};
|
|
31
|
+
DdEvent.prototype.emit = function (name) {
|
|
32
|
+
var args = [];
|
|
33
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
34
|
+
args[_i - 1] = arguments[_i];
|
|
35
|
+
}
|
|
36
|
+
var set = this._map.get(name);
|
|
37
|
+
if (!set)
|
|
38
|
+
return this;
|
|
39
|
+
var copied = __spreadArray([], set, true);
|
|
40
|
+
copied.forEach(function (fn) { return fn.apply(void 0, args); });
|
|
41
|
+
return this;
|
|
42
|
+
};
|
|
43
|
+
DdEvent.prototype.off = function (name, handler) {
|
|
44
|
+
if (name === void 0) { name = ""; }
|
|
45
|
+
// 什么都不传,则清除所有事件
|
|
46
|
+
if (!name) {
|
|
47
|
+
this._map.clear();
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
if (!handler) {
|
|
51
|
+
this._map.delete(name.toString());
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
var handlers = this._map.get(name);
|
|
55
|
+
if (!handlers) {
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
handlers.delete(handler);
|
|
59
|
+
return this;
|
|
60
|
+
};
|
|
61
|
+
DdEvent.prototype.once = function (name, handler) {
|
|
62
|
+
var _this = this;
|
|
63
|
+
var warpper = function () {
|
|
64
|
+
var args = [];
|
|
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);
|
|
70
|
+
};
|
|
71
|
+
this.on(name, warpper);
|
|
72
|
+
return this;
|
|
73
|
+
};
|
|
74
|
+
DdEvent.prototype.has = function (name) {
|
|
75
|
+
return this._map.has(name);
|
|
76
|
+
};
|
|
77
|
+
return DdEvent;
|
|
78
|
+
}());
|
|
79
|
+
exports.default = DdEvent;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var _Symbol_1 = require("./_Symbol");
|
|
4
|
+
var _a = Object.prototype, toString = _a.toString, hasOwnProperty = _a.hasOwnProperty, propertyIsEnumerable = _a.propertyIsEnumerable;
|
|
5
|
+
/** Built-in value references. */
|
|
6
|
+
var symToStringTag = _Symbol_1.default ? _Symbol_1.default.toStringTag : undefined;
|
|
7
|
+
function getRawTag(value) {
|
|
8
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag);
|
|
9
|
+
var tag = value[symToStringTag];
|
|
10
|
+
var unmasked = false;
|
|
11
|
+
try {
|
|
12
|
+
value[symToStringTag] = undefined;
|
|
13
|
+
unmasked = true;
|
|
14
|
+
}
|
|
15
|
+
catch (e) { }
|
|
16
|
+
var result = toString.call(value);
|
|
17
|
+
if (unmasked) {
|
|
18
|
+
if (isOwn) {
|
|
19
|
+
value[symToStringTag] = tag;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
delete value[symToStringTag];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
function getTag(value) {
|
|
28
|
+
if (value == null) {
|
|
29
|
+
return value === undefined ? "[object Undefined]" : "[object Null]";
|
|
30
|
+
}
|
|
31
|
+
return (symToStringTag && symToStringTag in Object(value))
|
|
32
|
+
? getRawTag(value)
|
|
33
|
+
: toString.call(value);
|
|
34
|
+
}
|
|
35
|
+
function getType(value) {
|
|
36
|
+
var str = getTag(value);
|
|
37
|
+
var mat = str.match(/\w+/g) || ["object", "Undefined"];
|
|
38
|
+
return mat[1] || "";
|
|
39
|
+
}
|
|
40
|
+
exports.default = { getTag: getTag, getType: getType, toString: toString, hasOwnProperty: hasOwnProperty, propertyIsEnumerable: propertyIsEnumerable };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var _freeGlobal_1 = require("./_freeGlobal");
|
|
4
|
+
/** Detect free variable `self`. */
|
|
5
|
+
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
|
6
|
+
/** Used as a reference to the global object. */
|
|
7
|
+
var root = _freeGlobal_1.default || freeSelf || Function('return this')();
|
|
8
|
+
exports.default = root;
|