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,184 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const string_1 = require("../string");
|
|
4
|
-
const copy = (source, options = {}) => {
|
|
5
|
-
if (source === undefined)
|
|
6
|
-
return undefined;
|
|
7
|
-
const newData = JSON.parse(JSON.stringify(source));
|
|
8
|
-
if (typeof newData !== 'object')
|
|
9
|
-
return newData;
|
|
10
|
-
if (Array.isArray(newData))
|
|
11
|
-
return newData;
|
|
12
|
-
const { fields = [], camel = false, pure = true } = options;
|
|
13
|
-
if ((!fields || fields.length <= 0) && !camel)
|
|
14
|
-
return newData;
|
|
15
|
-
const result = {};
|
|
16
|
-
for (const key in newData) {
|
|
17
|
-
if (!newData.hasOwnProperty(key))
|
|
18
|
-
continue;
|
|
19
|
-
const _key = camel ? (pure && key.startsWith('_') ? key : string_1.default.camelCase(key)) : key;
|
|
20
|
-
if (fields.length > 0 && !fields.includes(key) && !fields.includes(_key))
|
|
21
|
-
continue;
|
|
22
|
-
const value = newData[key];
|
|
23
|
-
if (options.ignoreNull && value === null)
|
|
24
|
-
continue;
|
|
25
|
-
if (options.ignoreZero && value === 0)
|
|
26
|
-
continue;
|
|
27
|
-
if (options.ignoreEmptyArray && Array.isArray(value) && value.length <= 0)
|
|
28
|
-
continue;
|
|
29
|
-
if (options.ignoreEmptyString && typeof value === 'string' && value.trim() === '')
|
|
30
|
-
continue;
|
|
31
|
-
result[_key] = value;
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* 克隆实体对象
|
|
37
|
-
* @param source
|
|
38
|
-
* @returns
|
|
39
|
-
*/
|
|
40
|
-
const clone = (source) => {
|
|
41
|
-
if (!source)
|
|
42
|
-
return source;
|
|
43
|
-
if (typeof source !== 'object')
|
|
44
|
-
return source;
|
|
45
|
-
const result = Array.isArray(source) ? [] : {};
|
|
46
|
-
for (const key in source) {
|
|
47
|
-
if (source.hasOwnProperty(key)) {
|
|
48
|
-
result[key] = clone(source[key]);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
|
-
};
|
|
53
|
-
function cloneClass(source) {
|
|
54
|
-
if (!source)
|
|
55
|
-
return source;
|
|
56
|
-
if (typeof source !== 'object')
|
|
57
|
-
return source;
|
|
58
|
-
return Object.create(Object.getPrototypeOf(source), Object.getOwnPropertyDescriptors(source));
|
|
59
|
-
}
|
|
60
|
-
const _merge = (target, source, options = {}) => {
|
|
61
|
-
const result = target || {};
|
|
62
|
-
const { ignoreUndefined = true, cover = false } = options;
|
|
63
|
-
if (!source)
|
|
64
|
-
return result;
|
|
65
|
-
for (const s in source) {
|
|
66
|
-
if (!source.hasOwnProperty(s))
|
|
67
|
-
continue;
|
|
68
|
-
const value = source[s];
|
|
69
|
-
if (typeof value === 'object' && typeof target[s] === 'object' && !cover) {
|
|
70
|
-
result[s] = merge(target[s], value, options);
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
if (ignoreUndefined && value === undefined)
|
|
74
|
-
continue;
|
|
75
|
-
if (options.ignoreNull && value === null)
|
|
76
|
-
continue;
|
|
77
|
-
if (options.ignoreZero && value === 0)
|
|
78
|
-
continue;
|
|
79
|
-
if (options.ignoreEmptyArray && Array.isArray(value) && value.length <= 0)
|
|
80
|
-
continue;
|
|
81
|
-
if (options.ignoreEmptyString && typeof value === 'string' && value.trim() === '')
|
|
82
|
-
continue;
|
|
83
|
-
result[s] = value;
|
|
84
|
-
}
|
|
85
|
-
return result;
|
|
86
|
-
};
|
|
87
|
-
// <T extends object>
|
|
88
|
-
const merge = (target, source, options = {}) => {
|
|
89
|
-
let result = {};
|
|
90
|
-
if (target && typeof target === 'object' && !Array.isArray(target)) {
|
|
91
|
-
result = _merge(target, source, options);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
result = _merge({ ...target }, source, options);
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
97
|
-
};
|
|
98
|
-
const combine = (target, source, options = {}) => {
|
|
99
|
-
return _merge({ ...target }, source, { cover: true, ...options });
|
|
100
|
-
};
|
|
101
|
-
const combines = (objs, options = {}) => {
|
|
102
|
-
let result = {};
|
|
103
|
-
if (!objs || objs.length <= 0)
|
|
104
|
-
return result;
|
|
105
|
-
const { ignoreUndefined = true, ignoreNull = true, ignoreZero = true, ignoreEmptyArray = true, ignoreEmptyString = true, cover = true, } = options;
|
|
106
|
-
objs.forEach((e) => (result = combine(result, e, {
|
|
107
|
-
ignoreUndefined,
|
|
108
|
-
ignoreNull,
|
|
109
|
-
ignoreZero,
|
|
110
|
-
ignoreEmptyArray,
|
|
111
|
-
ignoreEmptyString,
|
|
112
|
-
cover,
|
|
113
|
-
})));
|
|
114
|
-
return result;
|
|
115
|
-
};
|
|
116
|
-
const isEmpty = (source) => {
|
|
117
|
-
if (source === 0)
|
|
118
|
-
return false;
|
|
119
|
-
if (!source)
|
|
120
|
-
return true;
|
|
121
|
-
if (typeof source !== 'object')
|
|
122
|
-
return false;
|
|
123
|
-
if (Array.isArray(source))
|
|
124
|
-
return !source.length;
|
|
125
|
-
return Object.keys(source).length <= 0;
|
|
126
|
-
};
|
|
127
|
-
const parseValue = (source, { number = false, boolean = false } = {}) => {
|
|
128
|
-
if (!source && typeof source !== 'object')
|
|
129
|
-
return source;
|
|
130
|
-
for (const [key, value] of Object.entries(source)) {
|
|
131
|
-
if (typeof value === 'object' && value !== null) {
|
|
132
|
-
for (const [key2, value2] of Object.entries(value)) {
|
|
133
|
-
value[key2] = string_1.default.parseValue(value2, { number, boolean });
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
source[key] = string_1.default.parseValue(value, { number, boolean });
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return source;
|
|
141
|
-
};
|
|
142
|
-
const observe = (obj, key, watchFun, owner, deep = false) => {
|
|
143
|
-
if (!obj || !key || !watchFun)
|
|
144
|
-
return;
|
|
145
|
-
let val = obj[key];
|
|
146
|
-
if (val !== null && typeof val === 'object' && deep) {
|
|
147
|
-
Object.keys(val).forEach((item) => {
|
|
148
|
-
observe(val, item, watchFun, owner, deep);
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
Object.defineProperty(obj, key, {
|
|
152
|
-
configurable: true,
|
|
153
|
-
enumerable: true,
|
|
154
|
-
set: (value) => {
|
|
155
|
-
watchFun.call(owner, value, val);
|
|
156
|
-
val = value;
|
|
157
|
-
if (deep) {
|
|
158
|
-
observe(obj, key, watchFun, owner, deep);
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
get: () => {
|
|
162
|
-
return val;
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
const find = (obj, cb) => {
|
|
167
|
-
if (!obj)
|
|
168
|
-
return undefined;
|
|
169
|
-
if (typeof obj !== 'object')
|
|
170
|
-
return undefined;
|
|
171
|
-
return Object.entries(obj || {}).find(([key, value]) => !!(cb && cb(key, value)));
|
|
172
|
-
};
|
|
173
|
-
exports.default = {
|
|
174
|
-
copy,
|
|
175
|
-
clone,
|
|
176
|
-
merge,
|
|
177
|
-
isEmpty,
|
|
178
|
-
parseValue,
|
|
179
|
-
cloneClass,
|
|
180
|
-
combine,
|
|
181
|
-
combines,
|
|
182
|
-
observe,
|
|
183
|
-
find,
|
|
184
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const isNullOrUndefined = value => value === null || value === undefined;
|
|
4
|
-
const strictUriEncode = string => encodeURIComponent(string).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
5
|
-
exports.default = { isNullOrUndefined, strictUriEncode };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const _object_1 = require("../../common/_object");
|
|
4
|
-
const obj_1 = require("../obj");
|
|
5
|
-
const decode = function (qs, { sep = "&", eq = "=", max = 1000, multiple = true, uri = true, parseNumber = false, parseBoolean = false } = {}) {
|
|
6
|
-
sep = sep || '&';
|
|
7
|
-
eq = eq || '=';
|
|
8
|
-
const result = {};
|
|
9
|
-
if (typeof qs !== 'string' || qs.length === 0) {
|
|
10
|
-
return result;
|
|
11
|
-
}
|
|
12
|
-
const regexp = /\+/g;
|
|
13
|
-
qs = qs.split(sep);
|
|
14
|
-
const maxKeys = max || 1000;
|
|
15
|
-
let len = qs.length;
|
|
16
|
-
// maxKeys <= 0 means that we should not limit keys count
|
|
17
|
-
if (maxKeys > 0 && len > maxKeys) {
|
|
18
|
-
len = maxKeys;
|
|
19
|
-
}
|
|
20
|
-
for (let i = 0; i < len; ++i) {
|
|
21
|
-
let x = qs[i].replace(regexp, '%20'), idx = x.indexOf(eq), kstr, vstr, k, v;
|
|
22
|
-
if (idx >= 0) {
|
|
23
|
-
kstr = x.substr(0, idx);
|
|
24
|
-
vstr = x.substr(idx + 1);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
kstr = x;
|
|
28
|
-
vstr = '';
|
|
29
|
-
}
|
|
30
|
-
k = uri ? decodeURIComponent(kstr) : kstr;
|
|
31
|
-
v = uri ? decodeURIComponent(vstr) : vstr;
|
|
32
|
-
if (!_object_1.default.hasOwnProperty.call(result, k) || !multiple) {
|
|
33
|
-
result[k] = v;
|
|
34
|
-
}
|
|
35
|
-
else if (Array.isArray(result[k])) {
|
|
36
|
-
result[k].push(v);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
result[k] = [result[k], v];
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
obj_1.default.parseValue(result, { number: parseNumber, boolean: parseBoolean });
|
|
43
|
-
return result;
|
|
44
|
-
};
|
|
45
|
-
exports.default = decode;
|
|
@@ -1,53 +0,0 @@
|
|
|
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 _encodeURIComponent = function (v, uri = true) {
|
|
16
|
-
return uri ? encodeURIComponent(v) : v;
|
|
17
|
-
};
|
|
18
|
-
const encode = function (obj, { sep = "&", eq = "=", name = null, uri = true, cleanZero = false, cleanNull = false, cleanWhitespace = false } = {}) {
|
|
19
|
-
sep = sep || '&';
|
|
20
|
-
eq = eq || '=';
|
|
21
|
-
if (obj === null) {
|
|
22
|
-
obj = undefined;
|
|
23
|
-
}
|
|
24
|
-
if (typeof obj === 'object') {
|
|
25
|
-
return Object.keys(obj).map(function (k) {
|
|
26
|
-
const ks = _encodeURIComponent(stringifyPrimitive(k), uri) + eq;
|
|
27
|
-
const _v = obj[k];
|
|
28
|
-
if (Array.isArray(_v)) {
|
|
29
|
-
return _v.map(function (v) {
|
|
30
|
-
return ks + _encodeURIComponent(stringifyPrimitive(v), uri);
|
|
31
|
-
}).join(sep);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
if (isInvalid(_v, { cleanZero, cleanNull, cleanWhitespace }))
|
|
35
|
-
return "";
|
|
36
|
-
return ks + _encodeURIComponent(stringifyPrimitive(_v), uri);
|
|
37
|
-
}
|
|
38
|
-
}).filter(Boolean).join(sep);
|
|
39
|
-
}
|
|
40
|
-
if (!name)
|
|
41
|
-
return '';
|
|
42
|
-
return _encodeURIComponent(stringifyPrimitive(name), uri) + eq + _encodeURIComponent(stringifyPrimitive(obj), uri);
|
|
43
|
-
};
|
|
44
|
-
const isInvalid = function (v, { cleanZero = false, cleanNull = false, cleanWhitespace = false } = {}) {
|
|
45
|
-
if (cleanZero && v === 0)
|
|
46
|
-
return true;
|
|
47
|
-
if (cleanNull && (v === null || v === undefined))
|
|
48
|
-
return true;
|
|
49
|
-
if (cleanWhitespace && (typeof v === 'string' && v.trim() === ''))
|
|
50
|
-
return true;
|
|
51
|
-
return false;
|
|
52
|
-
};
|
|
53
|
-
exports.default = encode;
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const decode_1 = require("./decode");
|
|
4
|
-
const encode_1 = require("./encode");
|
|
5
|
-
const https = (url) => {
|
|
6
|
-
if (!url)
|
|
7
|
-
return url;
|
|
8
|
-
return url.replace(/^http[s]?/, 'https');
|
|
9
|
-
};
|
|
10
|
-
// const RegHost = /^(http[s]?):\/\/([\w.]+)(?::(\d+))?/
|
|
11
|
-
const RegHost = /^(https?):\/\/([\w.\_\-]+)(?::(\d+))?/;
|
|
12
|
-
const parseUrl = (url) => {
|
|
13
|
-
const hostInfo = parseHost(url);
|
|
14
|
-
const { origin = '', url: _url = '', query = '' } = hostInfo;
|
|
15
|
-
const pathInfo = parsePath(_url);
|
|
16
|
-
const params = (0, decode_1.default)(query, { multiple: true, uri: false });
|
|
17
|
-
const result = {
|
|
18
|
-
...hostInfo,
|
|
19
|
-
...pathInfo,
|
|
20
|
-
pathname: _url.substring(_url.indexOf(origin || '') + origin.length),
|
|
21
|
-
params,
|
|
22
|
-
};
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
const parsePath = (url) => {
|
|
26
|
-
const _url = (url || '').replace(/\\/g, '/').split('?')[0];
|
|
27
|
-
const mat = _url.match(/[\/]?([\w\_\-]+)[.]?[\w]*[?]?$/);
|
|
28
|
-
const page = mat ? mat[1] : '';
|
|
29
|
-
const idx = _url.lastIndexOf('/') + 1;
|
|
30
|
-
const name = _url.substring(idx);
|
|
31
|
-
const last = name.lastIndexOf('.');
|
|
32
|
-
const withoutExtension = name.substring(0, last) || '';
|
|
33
|
-
const extname = last >= 0 ? name.substring(last) : '';
|
|
34
|
-
const route = _url.substring(0, idx) || '';
|
|
35
|
-
return { route, page, name, withoutExtension, extname };
|
|
36
|
-
};
|
|
37
|
-
// const join = (...args: string[]) => {
|
|
38
|
-
// let arr: string[] = []
|
|
39
|
-
// args.forEach((e) => {
|
|
40
|
-
// const _s = e.trim().replace(/^\/*(.*?)\/*$/, '$1')
|
|
41
|
-
// if (_s.length <= 0) return
|
|
42
|
-
// if (/^(\w+):\/\//.test(_s)) {
|
|
43
|
-
// arr = [_s]
|
|
44
|
-
// } else {
|
|
45
|
-
// arr.push(_s)
|
|
46
|
-
// }
|
|
47
|
-
// })
|
|
48
|
-
// return arr.join('/')
|
|
49
|
-
// }
|
|
50
|
-
const join = (...args) => {
|
|
51
|
-
const result = [];
|
|
52
|
-
let hasProtocol = false;
|
|
53
|
-
args.forEach((part) => {
|
|
54
|
-
const trimmed = part.trim();
|
|
55
|
-
if (trimmed === '') {
|
|
56
|
-
// 忽略空段
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (/^(\w+):\/\//.test(trimmed)) {
|
|
60
|
-
// 处理带协议的路径,重置所有内容
|
|
61
|
-
result.length = 0;
|
|
62
|
-
result.push(trimmed);
|
|
63
|
-
hasProtocol = true;
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const segments = trimmed.split('/');
|
|
67
|
-
segments.forEach((segment) => {
|
|
68
|
-
if (segment === '.' || segment === '') {
|
|
69
|
-
// 忽略当前目录标志或多余的斜杠
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (segment === '..') {
|
|
73
|
-
// 返回上一级目录
|
|
74
|
-
if (result.length > 0 && result[result.length - 1] !== '..') {
|
|
75
|
-
result.pop();
|
|
76
|
-
}
|
|
77
|
-
else if (!hasProtocol) {
|
|
78
|
-
// 非协议情况下,保留多余的 ".."
|
|
79
|
-
result.push('..');
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
// 普通路径段,直接加入
|
|
84
|
-
result.push(segment);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
return result.join('/');
|
|
89
|
-
};
|
|
90
|
-
const parseHost = (url) => {
|
|
91
|
-
const result = {
|
|
92
|
-
href: url,
|
|
93
|
-
url: '',
|
|
94
|
-
origin: '',
|
|
95
|
-
protocol: '',
|
|
96
|
-
host: '',
|
|
97
|
-
port: '',
|
|
98
|
-
query: '',
|
|
99
|
-
};
|
|
100
|
-
if (!url)
|
|
101
|
-
return result;
|
|
102
|
-
const matches = url.match(RegHost);
|
|
103
|
-
if (!matches || matches.length < 4)
|
|
104
|
-
return result;
|
|
105
|
-
const port = matches[3] || '';
|
|
106
|
-
const arr = url.split('?');
|
|
107
|
-
result.url = arr[0];
|
|
108
|
-
result.origin = matches[0];
|
|
109
|
-
result.protocol = `${matches[1]}:`;
|
|
110
|
-
result.host = `${matches[2]}${port ? ':' + port : ''}`;
|
|
111
|
-
result.port = port;
|
|
112
|
-
result.query = arr.length > 1 ? arr[1] : '';
|
|
113
|
-
return result;
|
|
114
|
-
};
|
|
115
|
-
const shExpMatch = (text, pattern) => {
|
|
116
|
-
if (text === pattern)
|
|
117
|
-
return true;
|
|
118
|
-
if (!text)
|
|
119
|
-
return false;
|
|
120
|
-
if (!pattern)
|
|
121
|
-
return false;
|
|
122
|
-
if (pattern === '*')
|
|
123
|
-
return true;
|
|
124
|
-
// 将模式转换为正则表达式
|
|
125
|
-
const regexPattern = pattern
|
|
126
|
-
.replace(/\./g, '\\.') // 转义 .
|
|
127
|
-
.replace(/\*/g, '.*') // 将 * 转换为 .*
|
|
128
|
-
.replace(/\?/g, '.'); // 将 ? 转换为 .
|
|
129
|
-
// const regex = new RegExp(regexPattern)
|
|
130
|
-
const regex = new RegExp('^' + regexPattern + '$');
|
|
131
|
-
return regex.test(text);
|
|
132
|
-
};
|
|
133
|
-
const isLocalIpAddress = (addr) => {
|
|
134
|
-
if (!addr)
|
|
135
|
-
return false;
|
|
136
|
-
if (shExpMatch(addr, '127.0.0.1') ||
|
|
137
|
-
shExpMatch(addr, 'localhost') ||
|
|
138
|
-
shExpMatch(addr, '192.168.*.*'))
|
|
139
|
-
return true;
|
|
140
|
-
return false;
|
|
141
|
-
};
|
|
142
|
-
exports.default = {
|
|
143
|
-
parse: decode_1.default,
|
|
144
|
-
stringify: encode_1.default,
|
|
145
|
-
https,
|
|
146
|
-
parseUrl,
|
|
147
|
-
parsePath,
|
|
148
|
-
parseHost,
|
|
149
|
-
join,
|
|
150
|
-
shExpMatch,
|
|
151
|
-
isLocalIpAddress,
|
|
152
|
-
};
|
package/bin/lib/modules/regex.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const regex = (patt, modifiers) => new RegExp(patt, modifiers);
|
|
4
|
-
const pattern = {
|
|
5
|
-
num: "0-9",
|
|
6
|
-
zh: "\u4E00-\u9FA5",
|
|
7
|
-
en: "A-Za-z",
|
|
8
|
-
};
|
|
9
|
-
const entire = {
|
|
10
|
-
chinese: /^[\u4E00-\u9FA5]+$/,
|
|
11
|
-
real: /^(\-|\+)?\d+(\.\d+)?$/,
|
|
12
|
-
cssReal: /^(\-|\+)?\d*(\.)?\d+$/,
|
|
13
|
-
id: /^[A-Za-z0-9]+$/,
|
|
14
|
-
yyyyMMdd: /^(\d{4})-?(\d{2})-?(\d{2})$/,
|
|
15
|
-
};
|
|
16
|
-
exports.default = { pattern, regex, entire };
|
package/bin/lib/modules/rsa.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const rsa_1 = require("./crypto/rsa");
|
|
4
|
-
const __subtle = ((typeof window !== 'undefined') ? window.crypto.subtle : {});
|
|
5
|
-
const generateKeys = () => rsa_1.default.generateKeys(__subtle);
|
|
6
|
-
// SHA256: 256 - 2 - 2*32 = 190
|
|
7
|
-
// SHA1: 256 - 2 - 2*20 = 214
|
|
8
|
-
const encrypt = async (data, publicKey) => rsa_1.default.encrypt(__subtle, data, publicKey);
|
|
9
|
-
const decrypt = async (encryptedBase64, privateKey) => rsa_1.default.decrypt(__subtle, encryptedBase64, privateKey);
|
|
10
|
-
const encode = async (data) => rsa_1.default.encrypt(__subtle, data, rsa_1.default.RSAPublicKey);
|
|
11
|
-
const decode = async (encryptedBase64) => rsa_1.default.decrypt(__subtle, encryptedBase64, rsa_1.default.RSAPrivateKey);
|
|
12
|
-
exports.default = {
|
|
13
|
-
generateKeys,
|
|
14
|
-
encrypt,
|
|
15
|
-
decrypt,
|
|
16
|
-
encode,
|
|
17
|
-
decode,
|
|
18
|
-
};
|