ddan-js 2.9.4 → 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.esm.js +1 -1
- package/bin/ddan-js.js +1 -1
- package/bin/types/browser.d.ts +1 -1
- package/bin/types/index.d.ts +2 -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 -152
- 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,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const convert_1 = require("../convert");
|
|
4
|
-
const delta = 0x9e3779b9; // 常量 Delta
|
|
5
|
-
const TEAKey = "33576f37387276645054657a6831686e454664424e5652456f47794835795942";
|
|
6
|
-
const encrypt = (v, teaKey) => {
|
|
7
|
-
let sum = 0;
|
|
8
|
-
const n = 32; // 32轮加密
|
|
9
|
-
for (let i = 0; i < n; i++) {
|
|
10
|
-
sum = (sum + delta) >>> 0;
|
|
11
|
-
v[0] = (v[0] + (((v[1] << 4) + teaKey[0]) ^ (v[1] + sum) ^ ((v[1] >>> 5) + teaKey[1]))) >>> 0;
|
|
12
|
-
v[1] = (v[1] + (((v[0] << 4) + teaKey[2]) ^ (v[0] + sum) ^ ((v[0] >>> 5) + teaKey[3]))) >>> 0;
|
|
13
|
-
}
|
|
14
|
-
return v;
|
|
15
|
-
};
|
|
16
|
-
const decrypt = (v, teaKey) => {
|
|
17
|
-
const n = 32; // 32轮解密
|
|
18
|
-
let sum = (delta * n) >>> 0;
|
|
19
|
-
for (let i = 0; i < n; i++) {
|
|
20
|
-
v[1] = (v[1] - (((v[0] << 4) + teaKey[2]) ^ (v[0] + sum) ^ ((v[0] >>> 5) + teaKey[3]))) >>> 0;
|
|
21
|
-
v[0] = (v[0] - (((v[1] << 4) + teaKey[0]) ^ (v[1] + sum) ^ ((v[1] >>> 5) + teaKey[1]))) >>> 0;
|
|
22
|
-
sum = (sum - delta) >>> 0;
|
|
23
|
-
}
|
|
24
|
-
return v;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* TEA KEY
|
|
28
|
-
* @param str 位
|
|
29
|
-
* @returns 4组32位
|
|
30
|
-
*/
|
|
31
|
-
const toTeaKey = (str) => {
|
|
32
|
-
const keyBytes = convert_1.default.str2bytes(str);
|
|
33
|
-
const key = new Uint32Array(4);
|
|
34
|
-
key[0] = (keyBytes[0] << 24) | (keyBytes[1] << 16) | (keyBytes[2] << 8) | keyBytes[3];
|
|
35
|
-
key[1] = (keyBytes[4] << 24) | (keyBytes[5] << 16) | (keyBytes[6] << 8) | keyBytes[7];
|
|
36
|
-
key[2] = (keyBytes[8] << 24) | (keyBytes[9] << 16) | (keyBytes[10] << 8) | keyBytes[11];
|
|
37
|
-
key[3] = (keyBytes[12] << 24) | (keyBytes[13] << 16) | (keyBytes[14] << 8) | keyBytes[15];
|
|
38
|
-
return key;
|
|
39
|
-
};
|
|
40
|
-
const encodeBytes = (plainbytes, key) => {
|
|
41
|
-
// 转换明文为字节数组并进行PKCS#7填充
|
|
42
|
-
const padded = convert_1.default.pkcs7Padding(plainbytes, 8);
|
|
43
|
-
// 将明文分块并加密
|
|
44
|
-
const key4LongBytes = toTeaKey(key);
|
|
45
|
-
const encryptedBlocks = [];
|
|
46
|
-
for (let i = 0; i < padded.length; i += 8) {
|
|
47
|
-
const block = convert_1.default.bytesToUint32(padded.slice(i, i + 8));
|
|
48
|
-
const encryptedBlock = encrypt(block, key4LongBytes);
|
|
49
|
-
encryptedBlocks.push(convert_1.default.uint32ToBytes(encryptedBlock));
|
|
50
|
-
}
|
|
51
|
-
const encoded = convert_1.default.concatBytes(...encryptedBlocks);
|
|
52
|
-
return encoded;
|
|
53
|
-
};
|
|
54
|
-
const decodeBytes = (cipherbytes, key) => {
|
|
55
|
-
// 将密文分块并解密
|
|
56
|
-
const key4LongBytes = toTeaKey(key);
|
|
57
|
-
const decryptedBlocks = [];
|
|
58
|
-
for (let i = 0; i < cipherbytes.length; i += 8) {
|
|
59
|
-
const block = convert_1.default.bytesToUint32(cipherbytes.slice(i, i + 8));
|
|
60
|
-
const decryptedBlock = decrypt(block, key4LongBytes);
|
|
61
|
-
decryptedBlocks.push(convert_1.default.uint32ToBytes(decryptedBlock));
|
|
62
|
-
}
|
|
63
|
-
const decryptedBytes = convert_1.default.concatBytes(...decryptedBlocks);
|
|
64
|
-
// 去除填充并返回明文
|
|
65
|
-
const decryptedUnpaddBytes = convert_1.default.pkcs7Unpadding(decryptedBytes);
|
|
66
|
-
return decryptedUnpaddBytes;
|
|
67
|
-
};
|
|
68
|
-
const encode = (plaintext, key) => {
|
|
69
|
-
// 转换明文为字节数组并进行PKCS#7填充
|
|
70
|
-
const plainBytes = convert_1.default.textEncode(plaintext);
|
|
71
|
-
const encoded = encodeBytes(plainBytes, key);
|
|
72
|
-
return convert_1.default.bytesToBase64(encoded);
|
|
73
|
-
};
|
|
74
|
-
const decode = (ciphertext, key) => {
|
|
75
|
-
const cipherBytes = convert_1.default.base64ToBytes(ciphertext);
|
|
76
|
-
const decryptedBytes = decodeBytes(cipherBytes, key);
|
|
77
|
-
return convert_1.default.textDecode(decryptedBytes.buffer);
|
|
78
|
-
};
|
|
79
|
-
exports.default = { TEAKey, encrypt, decrypt, toTeaKey, encode, decode, encodeBytes, decodeBytes };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const const_1 = require("./const");
|
|
4
|
-
/**
|
|
5
|
-
* 生成随机ID
|
|
6
|
-
* @param len id长度,0默认为uuid xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx 格式
|
|
7
|
-
* @param radix KeyChars 涉及的长度
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
const uuid = (len = 0, radix = 0) => {
|
|
11
|
-
const chars = const_1.default.keyChars.split('');
|
|
12
|
-
const result = [];
|
|
13
|
-
let i;
|
|
14
|
-
radix = radix || chars.length;
|
|
15
|
-
if (len) {
|
|
16
|
-
// Compact form
|
|
17
|
-
for (i = 0; i < len; i++)
|
|
18
|
-
result[i] = chars[0 | Math.random() * radix];
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
let r;
|
|
22
|
-
result[8] = result[13] = result[18] = result[23] = '-';
|
|
23
|
-
result[14] = '4';
|
|
24
|
-
// Fill in random data. At i==19 set the high bits of clock sequence as
|
|
25
|
-
for (i = 0; i < 36; i++) {
|
|
26
|
-
if (!result[i]) {
|
|
27
|
-
r = 0 | Math.random() * 16;
|
|
28
|
-
result[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return result.join('');
|
|
33
|
-
};
|
|
34
|
-
exports.default = uuid;
|
package/bin/lib/modules/css.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const util_1 = require("../util");
|
|
4
|
-
const qs_1 = require("./qs");
|
|
5
|
-
const rule_1 = require("./rule");
|
|
6
|
-
const string_1 = require("./string");
|
|
7
|
-
const stringify = (styleObj) => {
|
|
8
|
-
if (!styleObj)
|
|
9
|
-
return '';
|
|
10
|
-
if (!util_1.default.isObject(styleObj))
|
|
11
|
-
return '';
|
|
12
|
-
let result = '';
|
|
13
|
-
util_1.default.forof(styleObj, (k, v) => {
|
|
14
|
-
if (!v)
|
|
15
|
-
return;
|
|
16
|
-
result += `${string_1.default.kebabCase(k)}:${v};`;
|
|
17
|
-
});
|
|
18
|
-
return result;
|
|
19
|
-
};
|
|
20
|
-
const parse = (styleStr, { camel = false, pure = true } = {}) => {
|
|
21
|
-
if (!styleStr.trim())
|
|
22
|
-
return undefined;
|
|
23
|
-
const ret = qs_1.default.parse(styleStr, { sep: ';', eq: ':', uri: false });
|
|
24
|
-
const result = {};
|
|
25
|
-
util_1.default.forof(ret, (k, v) => {
|
|
26
|
-
if (!v)
|
|
27
|
-
return;
|
|
28
|
-
const _k = camel ? ((pure && k.startsWith("_")) ? k : string_1.default.camelCase(k)) : k;
|
|
29
|
-
if (rule_1.default.isFloat(v)) {
|
|
30
|
-
result[_k] = +v;
|
|
31
|
-
}
|
|
32
|
-
else if (v.length >= 2 && v.startsWith('.') && rule_1.default.isNumber(v.substr(1))) {
|
|
33
|
-
result[_k] = +v;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
result[_k] = v;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
const commonFields = [
|
|
42
|
-
"display",
|
|
43
|
-
"position",
|
|
44
|
-
"top",
|
|
45
|
-
"bottom",
|
|
46
|
-
"left",
|
|
47
|
-
"right",
|
|
48
|
-
"padding",
|
|
49
|
-
"margin",
|
|
50
|
-
"marginTop",
|
|
51
|
-
"marginRight",
|
|
52
|
-
"marginBottom",
|
|
53
|
-
"marginLeft",
|
|
54
|
-
"paddingTop",
|
|
55
|
-
"paddingRight",
|
|
56
|
-
"paddingBottom",
|
|
57
|
-
"paddingLeft",
|
|
58
|
-
"height",
|
|
59
|
-
"width",
|
|
60
|
-
"fontSize",
|
|
61
|
-
"textAlign",
|
|
62
|
-
"fontFamily",
|
|
63
|
-
"border",
|
|
64
|
-
"borderLeft",
|
|
65
|
-
"borderRight",
|
|
66
|
-
"borderTop",
|
|
67
|
-
"borderBottom",
|
|
68
|
-
"borderColor",
|
|
69
|
-
"borderRadius",
|
|
70
|
-
"background",
|
|
71
|
-
"backgroundImage",
|
|
72
|
-
"backgroundRepeat",
|
|
73
|
-
"backgroundSize",
|
|
74
|
-
"backgroundPosition",
|
|
75
|
-
"color",
|
|
76
|
-
"overflow",
|
|
77
|
-
"opacity",
|
|
78
|
-
"flexDirection",
|
|
79
|
-
"justifyContent",
|
|
80
|
-
"alignItems",
|
|
81
|
-
"flexWrap",
|
|
82
|
-
"alignContent",
|
|
83
|
-
"alignSelf",
|
|
84
|
-
"flex",
|
|
85
|
-
"flexBasis",
|
|
86
|
-
"flexFlow",
|
|
87
|
-
"flexShrink",
|
|
88
|
-
"pointerEvents",
|
|
89
|
-
];
|
|
90
|
-
const fixFields = [
|
|
91
|
-
"top",
|
|
92
|
-
"bottom",
|
|
93
|
-
"left",
|
|
94
|
-
"right",
|
|
95
|
-
"padding",
|
|
96
|
-
"margin",
|
|
97
|
-
"marginTop",
|
|
98
|
-
"marginRight",
|
|
99
|
-
"marginBottom",
|
|
100
|
-
"marginLeft",
|
|
101
|
-
"paddingTop",
|
|
102
|
-
"paddingRight",
|
|
103
|
-
"paddingBottom",
|
|
104
|
-
"paddingLeft",
|
|
105
|
-
"height",
|
|
106
|
-
"width",
|
|
107
|
-
"border",
|
|
108
|
-
"borderLeft",
|
|
109
|
-
"borderRight",
|
|
110
|
-
"borderTop",
|
|
111
|
-
"borderBottom",
|
|
112
|
-
"borderColor",
|
|
113
|
-
"borderRadius",
|
|
114
|
-
];
|
|
115
|
-
const style = (cssKV, unit = 'px') => {
|
|
116
|
-
if (!cssKV)
|
|
117
|
-
return "";
|
|
118
|
-
const _kv = util_1.default.copy(cssKV, { fields: commonFields });
|
|
119
|
-
util_1.default.forof(_kv, (k, v) => {
|
|
120
|
-
if (fixFields.includes(k) || fixFields.includes(string_1.default.camelCase(k))) {
|
|
121
|
-
_kv[k] = fixValue(v, unit);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
const result = stringify(_kv);
|
|
125
|
-
return result;
|
|
126
|
-
};
|
|
127
|
-
const fixValue = (value, unit = 'px') => {
|
|
128
|
-
if (!value || !unit)
|
|
129
|
-
return value;
|
|
130
|
-
if (value === '0')
|
|
131
|
-
return value;
|
|
132
|
-
if (rule_1.default.isFloat(value.toString())) {
|
|
133
|
-
return `${value}${unit}`;
|
|
134
|
-
}
|
|
135
|
-
return value;
|
|
136
|
-
};
|
|
137
|
-
exports.default = { stringify, parse, fixValue, style, commonFields };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.catchMethod = void 0;
|
|
4
|
-
const catchMethod = (_target, _methodName, descriptor) => {
|
|
5
|
-
const originalMethod = descriptor.value;
|
|
6
|
-
descriptor.value = function (...args) {
|
|
7
|
-
try {
|
|
8
|
-
return originalMethod.apply(this, args);
|
|
9
|
-
}
|
|
10
|
-
catch (err) {
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
exports.catchMethod = catchMethod;
|
package/bin/lib/modules/fetch.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_1 = require("./hook/base");
|
|
4
|
-
const convert_1 = require("./convert");
|
|
5
|
-
const math_1 = require("./math");
|
|
6
|
-
const getDataURL = (url, cache) => {
|
|
7
|
-
const result = {
|
|
8
|
-
contentType: '',
|
|
9
|
-
dataUrl: '',
|
|
10
|
-
};
|
|
11
|
-
return base_1.default.to(fetch(url, { cache })
|
|
12
|
-
.then((response) => {
|
|
13
|
-
result.contentType = response.headers.get('content-type') || '';
|
|
14
|
-
return response.arrayBuffer();
|
|
15
|
-
})
|
|
16
|
-
.then((data) => {
|
|
17
|
-
result.dataUrl = `data:${result.contentType};base64,` + convert_1.default.ab2str(data, true);
|
|
18
|
-
return result;
|
|
19
|
-
}));
|
|
20
|
-
};
|
|
21
|
-
const getArrayBuffer = async (url, cache) => {
|
|
22
|
-
return base_1.default.to(fetch(url, { cache }).then((response) => {
|
|
23
|
-
return response.arrayBuffer();
|
|
24
|
-
}));
|
|
25
|
-
};
|
|
26
|
-
const getJson = async (url, cache) => {
|
|
27
|
-
return base_1.default.to(fetch(url, { cache }).then((response) => {
|
|
28
|
-
return response.json();
|
|
29
|
-
}));
|
|
30
|
-
};
|
|
31
|
-
const getText = async (url, cache) => {
|
|
32
|
-
return base_1.default.to(fetch(url, { cache }).then((response) => {
|
|
33
|
-
return response.text();
|
|
34
|
-
}));
|
|
35
|
-
};
|
|
36
|
-
const cache = async (url, cache = 'force-cache') => {
|
|
37
|
-
return base_1.default.to(fetch(url, { cache }).then(() => {
|
|
38
|
-
return true;
|
|
39
|
-
}));
|
|
40
|
-
};
|
|
41
|
-
const download = (url, opts = {}) => {
|
|
42
|
-
return new Promise((resolve) => fetch(url)
|
|
43
|
-
.then(async (response) => {
|
|
44
|
-
if (!response.ok || response.status !== 200) {
|
|
45
|
-
throw new Error(response.statusText);
|
|
46
|
-
}
|
|
47
|
-
const contentLength = +(response.headers.get('content-length') || '');
|
|
48
|
-
const reader = response.body?.getReader();
|
|
49
|
-
let receivedLength = 0;
|
|
50
|
-
const chunks = [];
|
|
51
|
-
while (true) {
|
|
52
|
-
const { done, value } = await reader.read();
|
|
53
|
-
if (done) {
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
chunks.push(value);
|
|
57
|
-
receivedLength += value.length;
|
|
58
|
-
const percentage = math_1.default.float((100.0 * receivedLength) / contentLength, { digits: 2 });
|
|
59
|
-
opts?.progress && opts?.progress(percentage, receivedLength, contentLength);
|
|
60
|
-
}
|
|
61
|
-
const chunksAll = new Uint8Array(receivedLength);
|
|
62
|
-
let position = 0;
|
|
63
|
-
for (const chunk of chunks) {
|
|
64
|
-
chunksAll.set(chunk, position);
|
|
65
|
-
position += chunk.length;
|
|
66
|
-
}
|
|
67
|
-
opts?.success && opts?.success(chunksAll);
|
|
68
|
-
resolve(chunksAll);
|
|
69
|
-
})
|
|
70
|
-
.catch((err) => {
|
|
71
|
-
opts?.fail && opts?.fail(err);
|
|
72
|
-
resolve(undefined);
|
|
73
|
-
}));
|
|
74
|
-
};
|
|
75
|
-
exports.default = {
|
|
76
|
-
getDataURL,
|
|
77
|
-
getArrayBuffer,
|
|
78
|
-
getJson,
|
|
79
|
-
download,
|
|
80
|
-
getText,
|
|
81
|
-
cache,
|
|
82
|
-
};
|
package/bin/lib/modules/gbk.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param str
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
function gbkLength(str) {
|
|
9
|
-
let len = 0;
|
|
10
|
-
if (!str)
|
|
11
|
-
return 0;
|
|
12
|
-
for (let i = 0; i < str.length; i++) {
|
|
13
|
-
if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
|
|
14
|
-
len += 2;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
len++;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return len;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 根据gbk字符长度截取内容
|
|
24
|
-
* @param {string} source
|
|
25
|
-
* @param {number} len
|
|
26
|
-
*/
|
|
27
|
-
function gbkCut(source, len) {
|
|
28
|
-
if (!source || len <= 0)
|
|
29
|
-
return "";
|
|
30
|
-
let n = 0;
|
|
31
|
-
let idx = 0;
|
|
32
|
-
for (let i = 0; i < source.length; i++) {
|
|
33
|
-
if (source.charCodeAt(i) > 127 || source.charCodeAt(i) === 94) {
|
|
34
|
-
n += 2;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
n++;
|
|
38
|
-
}
|
|
39
|
-
if (n > len) {
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
idx = i;
|
|
43
|
-
}
|
|
44
|
-
return source.substr(0, idx + 1);
|
|
45
|
-
}
|
|
46
|
-
exports.default = { gbkLength, gbkCut };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const is_1 = require("../../util/is");
|
|
4
|
-
async function to(promise, errorExt, fn) {
|
|
5
|
-
return promise
|
|
6
|
-
.then((data) => {
|
|
7
|
-
fn && fn();
|
|
8
|
-
return [null, data];
|
|
9
|
-
})
|
|
10
|
-
.catch((err) => {
|
|
11
|
-
if (errorExt) {
|
|
12
|
-
Object.assign(err, errorExt);
|
|
13
|
-
}
|
|
14
|
-
fn && fn();
|
|
15
|
-
return [err, undefined];
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 延迟处理
|
|
20
|
-
* @param ms 延迟时间(ms),默认:1000ms
|
|
21
|
-
* @returns
|
|
22
|
-
*/
|
|
23
|
-
const delay = (ms = 1000) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
24
|
-
const safeRun = (func, fn) => {
|
|
25
|
-
try {
|
|
26
|
-
let temp;
|
|
27
|
-
if (is_1.default.isFunction(func)) {
|
|
28
|
-
temp = func();
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
temp = func;
|
|
32
|
-
}
|
|
33
|
-
// promise = is.isPromise(temp) ? temp : Promise.resolve(temp);
|
|
34
|
-
return to(Promise.resolve(temp), undefined, fn);
|
|
35
|
-
}
|
|
36
|
-
catch (err) {
|
|
37
|
-
fn && fn();
|
|
38
|
-
return Promise.resolve([err, undefined]);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const go = (task, fn) => safeRun(task, fn);
|
|
42
|
-
const toError = (value) => {
|
|
43
|
-
value = typeof value === 'function' ? value() : value;
|
|
44
|
-
return typeof value === 'string' ? new Error(value) : value;
|
|
45
|
-
};
|
|
46
|
-
const timeout = (task, ms = 0, desc = 'timeout') => {
|
|
47
|
-
if (ms <= 0) {
|
|
48
|
-
return safeRun(task);
|
|
49
|
-
}
|
|
50
|
-
let timerid;
|
|
51
|
-
function clear() {
|
|
52
|
-
timerid && clearTimeout(timerid);
|
|
53
|
-
}
|
|
54
|
-
const fn = new Promise((resolve) => {
|
|
55
|
-
clear();
|
|
56
|
-
timerid = setTimeout(() => resolve([toError(desc || 'timeout'), undefined]), ms);
|
|
57
|
-
});
|
|
58
|
-
return Promise.race([safeRun(task, clear), fn]);
|
|
59
|
-
};
|
|
60
|
-
exports.default = { to, go, delay, safeRun, toError, timeout };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const base_1 = require("./base");
|
|
4
|
-
const function_1 = require("../../util/function");
|
|
5
|
-
const pipeline_1 = require("./modules/pipeline");
|
|
6
|
-
class DHooker extends function_1.default.singleton() {
|
|
7
|
-
__lockedMap = new Map();
|
|
8
|
-
pipeline = new pipeline_1.default();
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
11
|
-
}
|
|
12
|
-
lock(id, func) {
|
|
13
|
-
if (!id || !func)
|
|
14
|
-
return undefined;
|
|
15
|
-
const task = base_1.default.safeRun(func);
|
|
16
|
-
this.__lockedMap.set(id, task);
|
|
17
|
-
return task;
|
|
18
|
-
}
|
|
19
|
-
unlock(id) {
|
|
20
|
-
if (!id)
|
|
21
|
-
return;
|
|
22
|
-
this.__lockedMap.has(id) && this.__lockedMap.delete(id);
|
|
23
|
-
}
|
|
24
|
-
async exec(func, taskId) {
|
|
25
|
-
if (!func || !taskId) {
|
|
26
|
-
return base_1.default.safeRun(func);
|
|
27
|
-
}
|
|
28
|
-
const _task = this.__lockedMap.get(taskId);
|
|
29
|
-
if (_task)
|
|
30
|
-
return _task;
|
|
31
|
-
const _newTask = this.lock(taskId, func);
|
|
32
|
-
if (!_newTask)
|
|
33
|
-
return base_1.default.safeRun(func);
|
|
34
|
-
const result = await _newTask;
|
|
35
|
-
this.unlock(taskId);
|
|
36
|
-
return result;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.default = DHooker;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const debounce_1 = require("./modules/debounce");
|
|
4
|
-
const throttle_1 = require("./modules/throttle");
|
|
5
|
-
const mutex_1 = require("./modules/mutex");
|
|
6
|
-
const pipeTask_1 = require("../../class/pipeTask");
|
|
7
|
-
const base_1 = require("./base");
|
|
8
|
-
const polling_1 = require("./modules/polling");
|
|
9
|
-
const hooker_1 = require("./hooker");
|
|
10
|
-
const pipeline_1 = require("./modules/pipeline");
|
|
11
|
-
const safeTask_1 = require("./modules/safeTask");
|
|
12
|
-
const log_1 = require("./log");
|
|
13
|
-
const bezier_1 = require("./modules/bezier");
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @param task 任务
|
|
17
|
-
* @param wait 最小等待时间,单位毫秒
|
|
18
|
-
* @returns
|
|
19
|
-
*/
|
|
20
|
-
async function run(task, wait = 0) {
|
|
21
|
-
if (wait <= 0)
|
|
22
|
-
return base_1.default.safeRun(task);
|
|
23
|
-
const _time = wait > 0 ? Date.now() : 0;
|
|
24
|
-
const result = await base_1.default.safeRun(task);
|
|
25
|
-
const delta = Date.now() - _time;
|
|
26
|
-
delta < wait && (await base_1.default.delay(wait - delta));
|
|
27
|
-
return result;
|
|
28
|
-
}
|
|
29
|
-
const exec = (func, taskId = '') => hooker_1.default.I.exec(func, taskId);
|
|
30
|
-
const pipe = (func, callback) => hooker_1.default.I.pipeline.push(func, callback);
|
|
31
|
-
const pipeline = (max = 1) => new pipeline_1.default(max);
|
|
32
|
-
const task = (param) => new pipeTask_1.default(param);
|
|
33
|
-
const safeTask = (func, callback) => new safeTask_1.default(func, callback);
|
|
34
|
-
exports.default = {
|
|
35
|
-
...base_1.default,
|
|
36
|
-
...log_1.default,
|
|
37
|
-
...bezier_1.default,
|
|
38
|
-
sleep: base_1.default.delay,
|
|
39
|
-
run,
|
|
40
|
-
exec,
|
|
41
|
-
debounce: debounce_1.default,
|
|
42
|
-
throttle: throttle_1.default,
|
|
43
|
-
task,
|
|
44
|
-
mutex: mutex_1.default,
|
|
45
|
-
polling: polling_1.default,
|
|
46
|
-
pipe,
|
|
47
|
-
pipeline,
|
|
48
|
-
safeTask,
|
|
49
|
-
};
|
|
@@ -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 };
|