ddan-js 2.9.3 → 2.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ddan-js.browser.js +1 -1
- package/bin/ddan-js.esm.js +1 -1
- package/bin/ddan-js.js +1 -1
- package/bin/types/browser.d.ts +3 -3
- package/bin/types/index.d.ts +4 -3
- package/bin/types/modules/fetch.d.ts +1 -1
- package/bin/types/modules/node/index.d.ts +2 -0
- package/package.json +18 -13
- package/bin/lib/browser.js +0 -111
- package/bin/lib/class/event.js +0 -104
- package/bin/lib/class/getset.js +0 -12
- package/bin/lib/class/icon.js +0 -94
- package/bin/lib/class/joker.js +0 -121
- package/bin/lib/class/kvalue.js +0 -29
- package/bin/lib/class/mapping.js +0 -82
- package/bin/lib/class/persist.js +0 -65
- package/bin/lib/class/pipeTask.js +0 -42
- package/bin/lib/class/pipeparallel.js +0 -24
- package/bin/lib/class/store.js +0 -87
- package/bin/lib/class/tracker.js +0 -125
- package/bin/lib/class/watermark.js +0 -63
- package/bin/lib/common/_Symbol.js +0 -5
- package/bin/lib/common/_freeGlobal.js +0 -5
- package/bin/lib/common/_object.js +0 -40
- package/bin/lib/common/_root.js +0 -10
- package/bin/lib/common/internal/asciiToArray.js +0 -13
- package/bin/lib/common/internal/castSlice.js +0 -18
- package/bin/lib/common/internal/createCaseFirst.js +0 -30
- package/bin/lib/common/internal/hasUnicode.js +0 -26
- package/bin/lib/common/internal/nodeTypes.js +0 -26
- package/bin/lib/common/internal/slice.js +0 -46
- package/bin/lib/common/internal/stringToArray.js +0 -18
- package/bin/lib/common/internal/unicodeToArray.js +0 -40
- package/bin/lib/common/internal/unicodeWords.js +0 -67
- package/bin/lib/index.js +0 -114
- package/bin/lib/modules/browser/ecdh.js +0 -124
- package/bin/lib/modules/browser/index.js +0 -4
- package/bin/lib/modules/cdn.js +0 -62
- package/bin/lib/modules/convert/base.js +0 -125
- package/bin/lib/modules/convert/base64.js +0 -114
- package/bin/lib/modules/convert/index.js +0 -99
- package/bin/lib/modules/convert/md5.js +0 -222
- package/bin/lib/modules/convert/pkcs.js +0 -16
- package/bin/lib/modules/convert/utf8.js +0 -106
- package/bin/lib/modules/crypto/base64.js +0 -14
- package/bin/lib/modules/crypto/const.js +0 -7
- package/bin/lib/modules/crypto/index.js +0 -30
- package/bin/lib/modules/crypto/rsa.js +0 -143
- package/bin/lib/modules/crypto/tea.js +0 -79
- package/bin/lib/modules/crypto/uuid.js +0 -34
- package/bin/lib/modules/css.js +0 -137
- package/bin/lib/modules/decorator.js +0 -14
- package/bin/lib/modules/fetch.js +0 -82
- package/bin/lib/modules/gbk.js +0 -46
- package/bin/lib/modules/hook/base.js +0 -60
- package/bin/lib/modules/hook/hooker.js +0 -39
- package/bin/lib/modules/hook/index.js +0 -49
- package/bin/lib/modules/hook/log.js +0 -54
- package/bin/lib/modules/hook/modules/bezier.js +0 -121
- package/bin/lib/modules/hook/modules/debounce.js +0 -127
- package/bin/lib/modules/hook/modules/mutex.js +0 -22
- package/bin/lib/modules/hook/modules/pipeline.js +0 -59
- package/bin/lib/modules/hook/modules/polling.js +0 -20
- package/bin/lib/modules/hook/modules/safeTask.js +0 -25
- package/bin/lib/modules/hook/modules/throttle.js +0 -30
- package/bin/lib/modules/html.js +0 -293
- package/bin/lib/modules/http/index.js +0 -171
- package/bin/lib/modules/http/interceptor.js +0 -22
- package/bin/lib/modules/list/base.js +0 -37
- package/bin/lib/modules/list/index.js +0 -90
- package/bin/lib/modules/logger.js +0 -55
- package/bin/lib/modules/math/index.js +0 -118
- package/bin/lib/modules/mini/diff.js +0 -97
- package/bin/lib/modules/mini/http/index.js +0 -155
- package/bin/lib/modules/mini/index.js +0 -71
- package/bin/lib/modules/node/aliyun.js +0 -156
- package/bin/lib/modules/node/brotli.js +0 -46
- package/bin/lib/modules/node/child.js +0 -18
- package/bin/lib/modules/node/ecdh-web.js +0 -11
- package/bin/lib/modules/node/ecdh.js +0 -115
- package/bin/lib/modules/node/file.js +0 -25
- package/bin/lib/modules/node/index.js +0 -11
- package/bin/lib/modules/node/proxy.js +0 -147
- package/bin/lib/modules/node/rsa-web.js +0 -19
- package/bin/lib/modules/node/socks5.js +0 -424
- package/bin/lib/modules/obj/index.js +0 -184
- package/bin/lib/modules/qs/base.js +0 -5
- package/bin/lib/modules/qs/decode.js +0 -45
- package/bin/lib/modules/qs/encode.js +0 -53
- package/bin/lib/modules/qs/index.js +0 -114
- package/bin/lib/modules/regex.js +0 -16
- package/bin/lib/modules/rsa.js +0 -18
- package/bin/lib/modules/rule/async-validator/index.js +0 -306
- package/bin/lib/modules/rule/async-validator/interface.js +0 -2
- package/bin/lib/modules/rule/async-validator/messages.js +0 -59
- package/bin/lib/modules/rule/async-validator/rule/enum.js +0 -13
- package/bin/lib/modules/rule/async-validator/rule/index.js +0 -16
- package/bin/lib/modules/rule/async-validator/rule/pattern.js +0 -27
- package/bin/lib/modules/rule/async-validator/rule/range.js +0 -54
- package/bin/lib/modules/rule/async-validator/rule/required.js +0 -12
- package/bin/lib/modules/rule/async-validator/rule/type.js +0 -98
- package/bin/lib/modules/rule/async-validator/rule/url.js +0 -55
- package/bin/lib/modules/rule/async-validator/rule/whitespace.js +0 -20
- package/bin/lib/modules/rule/async-validator/util.js +0 -255
- package/bin/lib/modules/rule/async-validator/validator/any.js +0 -16
- package/bin/lib/modules/rule/async-validator/validator/array.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/boolean.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/date.js +0 -31
- package/bin/lib/modules/rule/async-validator/validator/enum.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/float.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/index.js +0 -36
- package/bin/lib/modules/rule/async-validator/validator/integer.js +0 -20
- package/bin/lib/modules/rule/async-validator/validator/method.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/number.js +0 -23
- package/bin/lib/modules/rule/async-validator/validator/object.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/pattern.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/regexp.js +0 -19
- package/bin/lib/modules/rule/async-validator/validator/required.js +0 -10
- package/bin/lib/modules/rule/async-validator/validator/string.js +0 -24
- package/bin/lib/modules/rule/async-validator/validator/type.js +0 -20
- package/bin/lib/modules/rule/index.js +0 -67
- package/bin/lib/modules/string/index.js +0 -121
- package/bin/lib/modules/string/words.js +0 -33
- package/bin/lib/modules/time/const.js +0 -11
- package/bin/lib/modules/time/dtime.js +0 -132
- package/bin/lib/modules/time/frame.js +0 -49
- package/bin/lib/modules/time/index.js +0 -84
- package/bin/lib/typings/index.js +0 -2
- package/bin/lib/util/function.js +0 -33
- package/bin/lib/util/includes.js +0 -96
- package/bin/lib/util/index.js +0 -26
- package/bin/lib/util/is.js +0 -148
- package/bin/lib/util/to.js +0 -47
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const is_1 = require("../../util/is");
|
|
4
|
-
const rsa_web_1 = require("../node/rsa-web");
|
|
5
|
-
const rsa_1 = require("../rsa");
|
|
6
|
-
const tea_1 = require("../crypto/tea");
|
|
7
|
-
const convert_1 = require("../convert");
|
|
8
|
-
const string_1 = require("../string");
|
|
9
|
-
const logString = (data) => {
|
|
10
|
-
try {
|
|
11
|
-
const jsonString = JSON.stringify(data);
|
|
12
|
-
if (jsonString === undefined)
|
|
13
|
-
return '';
|
|
14
|
-
return tea_1.default.encode(jsonString, convert_1.default.hex2str(tea_1.default.TEAKey));
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
return '';
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const logParse = (logStr) => {
|
|
21
|
-
try {
|
|
22
|
-
if (!logStr)
|
|
23
|
-
return '';
|
|
24
|
-
const ret = tea_1.default.decode(logStr, convert_1.default.hex2str(tea_1.default.TEAKey));
|
|
25
|
-
return string_1.default.jsonFormat(ret);
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
return '';
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const logRString = async (data) => {
|
|
32
|
-
try {
|
|
33
|
-
const jsonString = JSON.stringify(data);
|
|
34
|
-
if (jsonString === undefined)
|
|
35
|
-
return '';
|
|
36
|
-
const ret = is_1.default.isBrowser ? await rsa_1.default.encode(jsonString) : await rsa_web_1.default.encode(jsonString);
|
|
37
|
-
return ret;
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
return '';
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const logRParse = async (logStr) => {
|
|
44
|
-
try {
|
|
45
|
-
if (!logStr)
|
|
46
|
-
return '';
|
|
47
|
-
const ret = is_1.default.isBrowser ? await rsa_1.default.decode(logStr) : await rsa_web_1.default.decode(logStr);
|
|
48
|
-
return string_1.default.jsonFormat(ret);
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
return '';
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
exports.default = { logString, logParse, logRString, logRParse };
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const lerp = (start, end, t) => {
|
|
4
|
-
// (1 - t) * p0.x + t * p1.x,
|
|
5
|
-
return start * (1 - t) + end * t;
|
|
6
|
-
};
|
|
7
|
-
const proportion = (start, end, current) => {
|
|
8
|
-
if (start === end)
|
|
9
|
-
return 0;
|
|
10
|
-
return (current - start) / (end - start);
|
|
11
|
-
};
|
|
12
|
-
const bezier1 = (p0, p1, t) => {
|
|
13
|
-
return {
|
|
14
|
-
x: lerp(p0.x, p1.x, t),
|
|
15
|
-
y: lerp(p0.y, p1.y, t),
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
const bezier2 = (p0, p1, p2, t) => {
|
|
19
|
-
const q0 = bezier1(p0, p1, t);
|
|
20
|
-
const q1 = bezier1(p1, p2, t);
|
|
21
|
-
return bezier1(q0, q1, t);
|
|
22
|
-
};
|
|
23
|
-
const bezier3 = (p0, p1, p2, p3, t) => {
|
|
24
|
-
const q0 = bezier2(p0, p1, p2, t);
|
|
25
|
-
const q1 = bezier2(p1, p2, p3, t);
|
|
26
|
-
return bezier1(q0, q1, t);
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* 贝塞尔曲线
|
|
30
|
-
* @param points
|
|
31
|
-
* @param t [0, 1]
|
|
32
|
-
* @returns
|
|
33
|
-
*/
|
|
34
|
-
const bezier = (points, t) => {
|
|
35
|
-
if (points.length === 1) {
|
|
36
|
-
return points[0]; // 递归终点
|
|
37
|
-
}
|
|
38
|
-
const nextPoints = [];
|
|
39
|
-
for (let i = 0; i < points.length - 1; i++) {
|
|
40
|
-
nextPoints.push({
|
|
41
|
-
x: (1 - t) * points[i].x + t * points[i + 1].x,
|
|
42
|
-
y: (1 - t) * points[i].y + t * points[i + 1].y,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return bezier(nextPoints, t);
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* 计算二项式系数 C(n, k)
|
|
49
|
-
* @param n 阶数
|
|
50
|
-
* @param k 选择的点数
|
|
51
|
-
* @returns 二项式系数
|
|
52
|
-
*/
|
|
53
|
-
const binomialCoefficient = (n, k) => {
|
|
54
|
-
if (k === 0 || k === n)
|
|
55
|
-
return 1;
|
|
56
|
-
let res = 1;
|
|
57
|
-
for (let i = 1; i <= k; i++) {
|
|
58
|
-
res = (res * (n - i + 1)) / i;
|
|
59
|
-
}
|
|
60
|
-
return res;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* 贝塞尔曲线
|
|
64
|
-
* @param points
|
|
65
|
-
* @param t [0, 1]
|
|
66
|
-
* @returns
|
|
67
|
-
*/
|
|
68
|
-
const bezierCurve = (points, t) => {
|
|
69
|
-
const n = points.length - 1;
|
|
70
|
-
let x = 0;
|
|
71
|
-
let y = 0;
|
|
72
|
-
for (let i = 0; i <= n; i++) {
|
|
73
|
-
const coefficient = binomialCoefficient(n, i) * Math.pow(1 - t, n - i) * Math.pow(t, i);
|
|
74
|
-
x += coefficient * points[i].x;
|
|
75
|
-
y += coefficient * points[i].y;
|
|
76
|
-
}
|
|
77
|
-
return { x, y };
|
|
78
|
-
};
|
|
79
|
-
const lerpAverage = (points, step, //
|
|
80
|
-
type = '') => {
|
|
81
|
-
if (points.length <= 0)
|
|
82
|
-
return 0;
|
|
83
|
-
if (points.length === 1)
|
|
84
|
-
return points[0].x;
|
|
85
|
-
if (points.length === 2)
|
|
86
|
-
return lerp(points[0].y, points[1].y, 0.5);
|
|
87
|
-
const values = [];
|
|
88
|
-
// 调整下排序
|
|
89
|
-
const _points = points.slice().sort((a, b) => a.x - b.x);
|
|
90
|
-
const size = _points.length;
|
|
91
|
-
const start = _points[0].x;
|
|
92
|
-
const end = _points[size - 1].x;
|
|
93
|
-
// 遍历每个插值点
|
|
94
|
-
for (let axis = start; axis <= end; axis += step) {
|
|
95
|
-
let value = 0;
|
|
96
|
-
// 找到 t 所在区间 [t1, t2]
|
|
97
|
-
for (let i = 0; i < size - 1; i++) {
|
|
98
|
-
const p1 = _points[i];
|
|
99
|
-
const p2 = _points[i + 1];
|
|
100
|
-
if (axis >= p1.x && axis <= p2.x) {
|
|
101
|
-
if (type === 'lerp') {
|
|
102
|
-
const t = proportion(p1.x, p2.x, axis);
|
|
103
|
-
value = bezier1(p1, p2, t).y;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
// 取左侧值
|
|
107
|
-
value = p1.y;
|
|
108
|
-
}
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
// 如果 t 超出范围,使用最后一个已知值
|
|
113
|
-
if (axis > _points[size - 1].x) {
|
|
114
|
-
value = _points[size - 1].y;
|
|
115
|
-
}
|
|
116
|
-
values.push(value);
|
|
117
|
-
}
|
|
118
|
-
const sum = values.reduce((acc, val) => acc + val, 0);
|
|
119
|
-
return sum / values.length;
|
|
120
|
-
};
|
|
121
|
-
exports.default = { bezier1, bezier2, bezier3, bezier, bezierCurve, lerp, lerpAverage, proportion };
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const to_1 = require("../../../util/to");
|
|
4
|
-
const is_1 = require("../../../util/is");
|
|
5
|
-
const FUNC_ERROR_TEXT = 'Expected a function';
|
|
6
|
-
const nativeMax = Math.max;
|
|
7
|
-
const nativeMin = Math.min;
|
|
8
|
-
/**
|
|
9
|
-
* 防抖 一段时间内,规定时间间隔多次执行,回调触发一次
|
|
10
|
-
* @param func
|
|
11
|
-
* @param wait 默认 300
|
|
12
|
-
* @param options 参数:leading 开始执行, trailing结束执行
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
function debounce(func, wait = 300, options = {}) {
|
|
16
|
-
let lastArgs;
|
|
17
|
-
let lastThis;
|
|
18
|
-
let maxWait;
|
|
19
|
-
let result;
|
|
20
|
-
let timerId;
|
|
21
|
-
let lastCallTime;
|
|
22
|
-
let lastInvokeTime = 0;
|
|
23
|
-
let leading = false;
|
|
24
|
-
let maxing = false;
|
|
25
|
-
let trailing = true;
|
|
26
|
-
if (typeof func != 'function') {
|
|
27
|
-
throw new TypeError(FUNC_ERROR_TEXT);
|
|
28
|
-
}
|
|
29
|
-
wait = to_1.default.toNumber(wait) || 0;
|
|
30
|
-
if (is_1.default.isObject(options)) {
|
|
31
|
-
leading = !!options.leading;
|
|
32
|
-
maxing = 'maxWait' in options;
|
|
33
|
-
maxWait = maxing ? nativeMax(to_1.default.toNumber(options.maxWait) || 0, wait) : maxWait;
|
|
34
|
-
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
35
|
-
}
|
|
36
|
-
function invokeFunc(time) {
|
|
37
|
-
const args = lastArgs;
|
|
38
|
-
const thisArg = lastThis;
|
|
39
|
-
lastArgs = lastThis = undefined;
|
|
40
|
-
lastInvokeTime = time;
|
|
41
|
-
result = func.apply(thisArg, args);
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
function leadingEdge(time) {
|
|
45
|
-
// Reset any `maxWait` timer.
|
|
46
|
-
lastInvokeTime = time;
|
|
47
|
-
// Start the timer for the trailing edge.
|
|
48
|
-
timerId = setTimeout(timerExpired, wait);
|
|
49
|
-
// Invoke the leading edge.
|
|
50
|
-
return leading ? invokeFunc(time) : result;
|
|
51
|
-
}
|
|
52
|
-
function remainingWait(time) {
|
|
53
|
-
const timeSinceLastCall = time - lastCallTime;
|
|
54
|
-
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
55
|
-
const timeWaiting = wait - timeSinceLastCall;
|
|
56
|
-
return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
|
|
57
|
-
}
|
|
58
|
-
function shouldInvoke(time) {
|
|
59
|
-
const timeSinceLastCall = time - lastCallTime;
|
|
60
|
-
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
61
|
-
// Either this is the first call, activity has stopped and we're at the
|
|
62
|
-
// trailing edge, the system time has gone backwards and we're treating
|
|
63
|
-
// it as the trailing edge, or we've hit the `maxWait` limit.
|
|
64
|
-
return (lastCallTime === undefined ||
|
|
65
|
-
timeSinceLastCall >= wait ||
|
|
66
|
-
timeSinceLastCall < 0 ||
|
|
67
|
-
(maxing && timeSinceLastInvoke >= maxWait));
|
|
68
|
-
}
|
|
69
|
-
function timerExpired() {
|
|
70
|
-
const time = Date.now();
|
|
71
|
-
if (shouldInvoke(time)) {
|
|
72
|
-
return trailingEdge(time);
|
|
73
|
-
}
|
|
74
|
-
// Restart the timer.
|
|
75
|
-
timerId = setTimeout(timerExpired, remainingWait(time));
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
function trailingEdge(time) {
|
|
79
|
-
timerId = undefined;
|
|
80
|
-
// Only invoke if we have `lastArgs` which means `func` has been
|
|
81
|
-
// debounced at least once.
|
|
82
|
-
if (trailing && lastArgs) {
|
|
83
|
-
return invokeFunc(time);
|
|
84
|
-
}
|
|
85
|
-
lastArgs = lastThis = undefined;
|
|
86
|
-
return result;
|
|
87
|
-
}
|
|
88
|
-
function cancel() {
|
|
89
|
-
if (timerId !== undefined) {
|
|
90
|
-
clearTimeout(timerId);
|
|
91
|
-
}
|
|
92
|
-
lastInvokeTime = 0;
|
|
93
|
-
lastArgs = lastCallTime = lastThis = timerId = undefined;
|
|
94
|
-
}
|
|
95
|
-
function flush() {
|
|
96
|
-
return timerId === undefined ? result : trailingEdge(Date.now());
|
|
97
|
-
}
|
|
98
|
-
function pending() {
|
|
99
|
-
return timerId !== undefined;
|
|
100
|
-
}
|
|
101
|
-
function debounced(...args) {
|
|
102
|
-
const time = Date.now();
|
|
103
|
-
const isInvoking = shouldInvoke(time);
|
|
104
|
-
lastArgs = args;
|
|
105
|
-
lastThis = this;
|
|
106
|
-
lastCallTime = time;
|
|
107
|
-
if (isInvoking) {
|
|
108
|
-
if (timerId === undefined) {
|
|
109
|
-
return leadingEdge(lastCallTime);
|
|
110
|
-
}
|
|
111
|
-
if (maxing) {
|
|
112
|
-
// Handle invocations in a tight loop.
|
|
113
|
-
timerId = setTimeout(timerExpired, wait);
|
|
114
|
-
return invokeFunc(lastCallTime);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (timerId === undefined) {
|
|
118
|
-
timerId = setTimeout(timerExpired, wait);
|
|
119
|
-
}
|
|
120
|
-
return result;
|
|
121
|
-
}
|
|
122
|
-
debounced.cancel = cancel;
|
|
123
|
-
debounced.flush = flush;
|
|
124
|
-
debounced.pending = pending;
|
|
125
|
-
return debounced;
|
|
126
|
-
}
|
|
127
|
-
exports.default = debounce;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function mutex(func) {
|
|
4
|
-
var lastThis = null;
|
|
5
|
-
async function mutexed(...args) {
|
|
6
|
-
lastThis = this || lastThis || {};
|
|
7
|
-
if (lastThis.__ddMutex)
|
|
8
|
-
return false;
|
|
9
|
-
lastThis.__ddMutex = true;
|
|
10
|
-
try {
|
|
11
|
-
func && (await Promise.resolve(func.apply(this, args)));
|
|
12
|
-
}
|
|
13
|
-
catch (err) {
|
|
14
|
-
console.log(err);
|
|
15
|
-
}
|
|
16
|
-
finally {
|
|
17
|
-
lastThis.__ddMutex = false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return mutexed;
|
|
21
|
-
}
|
|
22
|
-
exports.default = mutex;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_1 = require("../base");
|
|
4
|
-
const safeTask_1 = require("./safeTask");
|
|
5
|
-
class DPipeline {
|
|
6
|
-
__list = [];
|
|
7
|
-
__count = 0;
|
|
8
|
-
__max = 1;
|
|
9
|
-
constructor(max = 1) {
|
|
10
|
-
this.__count = 0;
|
|
11
|
-
this.__max = max > 0 ? max : 1;
|
|
12
|
-
this.clear();
|
|
13
|
-
}
|
|
14
|
-
push(func, callback) {
|
|
15
|
-
const _sTask = new safeTask_1.default(func, callback);
|
|
16
|
-
this.__list.push(_sTask);
|
|
17
|
-
this._step();
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
clear() {
|
|
21
|
-
this.__list = [];
|
|
22
|
-
this.__count = 0;
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
_step() {
|
|
26
|
-
if (this.__list.length <= 0)
|
|
27
|
-
return;
|
|
28
|
-
if (this.__count >= this.__max)
|
|
29
|
-
return;
|
|
30
|
-
const _sTask = this.__list.shift();
|
|
31
|
-
if (_sTask) {
|
|
32
|
-
this.__count += 1;
|
|
33
|
-
_sTask?.run().finally(() => {
|
|
34
|
-
try {
|
|
35
|
-
if (this.__count > 0) {
|
|
36
|
-
this.__count -= 1;
|
|
37
|
-
}
|
|
38
|
-
this._step();
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
console.error('[ddan] pipepine step finally', err);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
this._step();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
async whenAll() {
|
|
50
|
-
do {
|
|
51
|
-
if (this.__count <= 0)
|
|
52
|
-
break;
|
|
53
|
-
await base_1.default.delay(100);
|
|
54
|
-
this._step();
|
|
55
|
-
} while (true);
|
|
56
|
-
return this.clear();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.default = DPipeline;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_1 = require("../base");
|
|
4
|
-
async function polling(params = {}) {
|
|
5
|
-
const { func, interval = 100, times = 1000 } = params;
|
|
6
|
-
let _times = times;
|
|
7
|
-
const _interval = interval < 1 ? 100 : interval;
|
|
8
|
-
do {
|
|
9
|
-
if (!func)
|
|
10
|
-
break;
|
|
11
|
-
const [err, res] = await base_1.default.to(Promise.resolve(func()));
|
|
12
|
-
if (err || res === false)
|
|
13
|
-
break;
|
|
14
|
-
if (_times > 0) {
|
|
15
|
-
_times--;
|
|
16
|
-
}
|
|
17
|
-
(_times !== 0) && await base_1.default.delay(_interval);
|
|
18
|
-
} while (times === -1 || _times > 0);
|
|
19
|
-
}
|
|
20
|
-
exports.default = polling;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_1 = require("../base");
|
|
4
|
-
class DSafeTask {
|
|
5
|
-
_func;
|
|
6
|
-
_callback;
|
|
7
|
-
constructor(task, callback) {
|
|
8
|
-
this._func = task;
|
|
9
|
-
this._callback = callback;
|
|
10
|
-
}
|
|
11
|
-
async run() {
|
|
12
|
-
return base_1.default.safeRun(this._func).then((res) => {
|
|
13
|
-
try {
|
|
14
|
-
this._callback && this._callback(res);
|
|
15
|
-
}
|
|
16
|
-
catch (err) {
|
|
17
|
-
console.log(`[ddan] task`, err);
|
|
18
|
-
}
|
|
19
|
-
finally {
|
|
20
|
-
return res;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.default = DSafeTask;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const is_1 = require("../../../util/is");
|
|
4
|
-
const debounce_1 = require("./debounce");
|
|
5
|
-
/** Error message constants. */
|
|
6
|
-
const FUNC_ERROR_TEXT = 'Expected a function';
|
|
7
|
-
/**
|
|
8
|
-
* 节流 每个间隔内,触发一次
|
|
9
|
-
* @param func
|
|
10
|
-
* @param wait 默认 300
|
|
11
|
-
* @param options 参数:leading 开始执行, trailing结束执行
|
|
12
|
-
* @returns
|
|
13
|
-
*/
|
|
14
|
-
function throttle(func, wait = 300, options = {}) {
|
|
15
|
-
let leading = true;
|
|
16
|
-
let trailing = true;
|
|
17
|
-
if (typeof func != 'function') {
|
|
18
|
-
throw new TypeError(FUNC_ERROR_TEXT);
|
|
19
|
-
}
|
|
20
|
-
if (is_1.default.isObject(options)) {
|
|
21
|
-
leading = options.leading ? !!options.leading : leading;
|
|
22
|
-
trailing = options.trailing ? !!options.trailing : trailing;
|
|
23
|
-
}
|
|
24
|
-
return (0, debounce_1.default)(func, wait, {
|
|
25
|
-
leading: leading,
|
|
26
|
-
maxWait: wait,
|
|
27
|
-
trailing: trailing
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
exports.default = throttle;
|