@maiyunnet/kebab 2.0.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/.VSCodeCounter/2025-02-14_14-46-44/details.md +82 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/diff-details.md +15 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.csv +2 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.md +19 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/diff.txt +22 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/results.csv +69 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/results.json +1 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/results.md +48 -0
- package/.VSCodeCounter/2025-02-14_14-46-44/results.txt +118 -0
- package/.vscode/tasks.json +15 -0
- package/LICENSE +201 -0
- package/README.md +201 -0
- package/bin/kebab.js +2 -0
- package/eslint.config.js +22 -0
- package/index.js +19 -0
- package/index.ts +33 -0
- package/lib/buffer.js +108 -0
- package/lib/buffer.ts +152 -0
- package/lib/captcha/zcool-addict-italic.ttf +0 -0
- package/lib/captcha.js +71 -0
- package/lib/captcha.ts +63 -0
- package/lib/consistent.js +171 -0
- package/lib/consistent.ts +219 -0
- package/lib/core.js +663 -0
- package/lib/core.ts +880 -0
- package/lib/crypto.js +256 -0
- package/lib/crypto.ts +384 -0
- package/lib/db.js +521 -0
- package/lib/db.ts +719 -0
- package/lib/dns.js +321 -0
- package/lib/dns.ts +405 -0
- package/lib/fs.js +405 -0
- package/lib/fs.ts +527 -0
- package/lib/jwt.js +223 -0
- package/lib/jwt.ts +276 -0
- package/lib/kv.js +1004 -0
- package/lib/kv.ts +1489 -0
- package/lib/lan.js +99 -0
- package/lib/lan.ts +87 -0
- package/lib/net/cacert.pem +3480 -0
- package/lib/net/formdata.js +137 -0
- package/lib/net/formdata.ts +166 -0
- package/lib/net/request.js +102 -0
- package/lib/net/request.ts +150 -0
- package/lib/net/response.js +28 -0
- package/lib/net/response.ts +59 -0
- package/lib/net.js +462 -0
- package/lib/net.ts +662 -0
- package/lib/s3.js +180 -0
- package/lib/s3.ts +235 -0
- package/lib/scan.js +276 -0
- package/lib/scan.ts +364 -0
- package/lib/session.js +177 -0
- package/lib/session.ts +230 -0
- package/lib/sql.js +818 -0
- package/lib/sql.ts +1151 -0
- package/lib/ssh/sftp.js +373 -0
- package/lib/ssh/sftp.ts +508 -0
- package/lib/ssh/shell.js +109 -0
- package/lib/ssh/shell.ts +123 -0
- package/lib/ssh.js +171 -0
- package/lib/ssh.ts +191 -0
- package/lib/text/tld.json +1 -0
- package/lib/text.js +452 -0
- package/lib/text.ts +607 -0
- package/lib/time.js +216 -0
- package/lib/time.ts +254 -0
- package/lib/ws.js +373 -0
- package/lib/ws.ts +523 -0
- package/lib/zip.js +381 -0
- package/lib/zip.ts +447 -0
- package/lib/zlib.js +289 -0
- package/lib/zlib.ts +350 -0
- package/main.js +51 -0
- package/main.ts +27 -0
- package/package.json +37 -0
- package/sys/child.js +585 -0
- package/sys/child.ts +678 -0
- package/sys/cmd.js +226 -0
- package/sys/cmd.ts +225 -0
- package/sys/ctr.js +608 -0
- package/sys/ctr.ts +904 -0
- package/sys/master.js +314 -0
- package/sys/master.ts +355 -0
- package/sys/mod.js +1273 -0
- package/sys/mod.ts +1871 -0
- package/sys/route.js +922 -0
- package/sys/route.ts +1113 -0
- package/types/index.d.ts +283 -0
- package/www/example/ctr/main.js +42 -0
- package/www/example/ctr/main.ts +9 -0
- package/www/example/ctr/middle.js +57 -0
- package/www/example/ctr/middle.ts +26 -0
- package/www/example/ctr/test.js +2818 -0
- package/www/example/ctr/test.ts +3218 -0
- package/www/example/data/locale/en.test.json +8 -0
- package/www/example/data/locale/index.html +1 -0
- package/www/example/data/locale/ja.test.json +8 -0
- package/www/example/data/locale/sc.test.json +8 -0
- package/www/example/data/locale/tc.test.json +8 -0
- package/www/example/data/test.zip +0 -0
- package/www/example/kebab.json +24 -0
- package/www/example/mod/test.js +49 -0
- package/www/example/mod/test.ts +47 -0
- package/www/example/mod/testdata.js +11 -0
- package/www/example/mod/testdata.ts +30 -0
- package/www/example/route.json +6 -0
- package/www/example/view/test.ejs +11 -0
- package/www/example/ws/mproxy.js +49 -0
- package/www/example/ws/mproxy.ts +16 -0
- package/www/example/ws/rproxy.js +47 -0
- package/www/example/ws/rproxy.ts +14 -0
- package/www/example/ws/test.js +68 -0
- package/www/example/ws/test.ts +36 -0
package/lib/text.js
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.REGEXP_ASCII = exports.REGEXP_DOMAIN = exports.REGEXP_IPV6 = exports.REGEXP_IPV4 = exports.REGEXP_EMAIL = void 0;
|
|
37
|
+
exports.sizeFormat = sizeFormat;
|
|
38
|
+
exports.parseUrl = parseUrl;
|
|
39
|
+
exports.urlResolve = urlResolve;
|
|
40
|
+
exports.urlAtom = urlAtom;
|
|
41
|
+
exports.isEMail = isEMail;
|
|
42
|
+
exports.isIPv4 = isIPv4;
|
|
43
|
+
exports.isIPv6 = isIPv6;
|
|
44
|
+
exports.isDomain = isDomain;
|
|
45
|
+
exports.isAscii = isAscii;
|
|
46
|
+
exports.nlReplace = nlReplace;
|
|
47
|
+
exports.parseDomain = parseDomain;
|
|
48
|
+
exports.match = match;
|
|
49
|
+
exports.isPhoneCN = isPhoneCN;
|
|
50
|
+
exports.isIdCardCN = isIdCardCN;
|
|
51
|
+
exports.queryStringify = queryStringify;
|
|
52
|
+
exports.queryParse = queryParse;
|
|
53
|
+
exports.htmlescape = htmlescape;
|
|
54
|
+
exports.isRealPath = isRealPath;
|
|
55
|
+
exports.getFilename = getFilename;
|
|
56
|
+
exports.stringifyResult = stringifyResult;
|
|
57
|
+
exports.parseJson = parseJson;
|
|
58
|
+
exports.stringifyJson = stringifyJson;
|
|
59
|
+
exports.str2int = str2int;
|
|
60
|
+
exports.int2str = int2str;
|
|
61
|
+
const kebab = __importStar(require("~/index"));
|
|
62
|
+
const fs = __importStar(require("./fs"));
|
|
63
|
+
function sizeFormat(size, spliter = ' ') {
|
|
64
|
+
const units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
|
65
|
+
let i = 0;
|
|
66
|
+
for (; i < 6 && size >= 1024.0; ++i) {
|
|
67
|
+
size /= 1024.0;
|
|
68
|
+
}
|
|
69
|
+
return (Math.round(size * 100) / 100).toString() + spliter + units[i];
|
|
70
|
+
}
|
|
71
|
+
function parseUrl(url) {
|
|
72
|
+
const rtn = {
|
|
73
|
+
'protocol': null,
|
|
74
|
+
'auth': null,
|
|
75
|
+
'user': null,
|
|
76
|
+
'pass': null,
|
|
77
|
+
'host': null,
|
|
78
|
+
'hostname': null,
|
|
79
|
+
'port': null,
|
|
80
|
+
'pathname': '/',
|
|
81
|
+
'path': null,
|
|
82
|
+
'query': null,
|
|
83
|
+
'hash': null
|
|
84
|
+
};
|
|
85
|
+
const hash = url.indexOf('#');
|
|
86
|
+
if (hash > -1) {
|
|
87
|
+
rtn['hash'] = url.slice(hash + 1);
|
|
88
|
+
url = url.slice(0, hash);
|
|
89
|
+
}
|
|
90
|
+
const query = url.indexOf('?');
|
|
91
|
+
if (query > -1) {
|
|
92
|
+
rtn['query'] = url.slice(query + 1);
|
|
93
|
+
url = url.slice(0, query);
|
|
94
|
+
}
|
|
95
|
+
const protocol = url.indexOf(':');
|
|
96
|
+
if (protocol > -1) {
|
|
97
|
+
rtn['protocol'] = url.slice(0, protocol + 1).toLowerCase();
|
|
98
|
+
url = url.slice(protocol + 1);
|
|
99
|
+
if (url.startsWith('//')) {
|
|
100
|
+
url = url.slice(2);
|
|
101
|
+
}
|
|
102
|
+
let path = url.indexOf('/');
|
|
103
|
+
if (path === -1) {
|
|
104
|
+
path = url.indexOf('\\');
|
|
105
|
+
}
|
|
106
|
+
if (path > -1) {
|
|
107
|
+
rtn['pathname'] = url.slice(path);
|
|
108
|
+
url = url.slice(0, path);
|
|
109
|
+
}
|
|
110
|
+
const auth = url.indexOf('@');
|
|
111
|
+
if (auth > -1) {
|
|
112
|
+
const authStr = url.slice(0, auth);
|
|
113
|
+
const authSplit = authStr.indexOf(':');
|
|
114
|
+
if (authSplit > -1) {
|
|
115
|
+
rtn['user'] = authStr.slice(0, authSplit);
|
|
116
|
+
rtn['pass'] = authStr.slice(authSplit + 1);
|
|
117
|
+
rtn['auth'] = rtn['user'] + ':' + rtn['pass'];
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
rtn['user'] = authStr;
|
|
121
|
+
rtn['auth'] = authStr;
|
|
122
|
+
}
|
|
123
|
+
url = url.slice(auth + 1);
|
|
124
|
+
}
|
|
125
|
+
if (url) {
|
|
126
|
+
const port = url.indexOf(':');
|
|
127
|
+
if (port > -1) {
|
|
128
|
+
rtn['hostname'] = url.slice(0, port).toLowerCase();
|
|
129
|
+
rtn['port'] = url.slice(port + 1);
|
|
130
|
+
rtn['host'] = rtn['hostname'] + (rtn['port'] ? ':' + rtn['port'] : '');
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
rtn['hostname'] = url.toLowerCase();
|
|
134
|
+
rtn['host'] = rtn['hostname'];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
rtn['pathname'] = url;
|
|
140
|
+
}
|
|
141
|
+
rtn['path'] = rtn['pathname'] + (rtn['query'] ? '?' + rtn['query'] : '');
|
|
142
|
+
return rtn;
|
|
143
|
+
}
|
|
144
|
+
function urlResolve(from, to) {
|
|
145
|
+
from = from.replace('\\', '/');
|
|
146
|
+
to = to.replace('\\', '/');
|
|
147
|
+
if (to === '') {
|
|
148
|
+
return urlAtom(from);
|
|
149
|
+
}
|
|
150
|
+
const f = parseUrl(from);
|
|
151
|
+
if (to.startsWith('//')) {
|
|
152
|
+
return urlAtom(f.protocol ? f.protocol + to : to);
|
|
153
|
+
}
|
|
154
|
+
if (f.protocol) {
|
|
155
|
+
from = f.protocol + from.slice(f.protocol.length);
|
|
156
|
+
}
|
|
157
|
+
const t = parseUrl(to);
|
|
158
|
+
if (t.protocol) {
|
|
159
|
+
return urlAtom(t.protocol + to.slice(t.protocol.length));
|
|
160
|
+
}
|
|
161
|
+
if (to.startsWith('#') || to.startsWith('?')) {
|
|
162
|
+
const sp = from.indexOf(to[0]);
|
|
163
|
+
if (sp !== -1) {
|
|
164
|
+
return urlAtom(from.slice(0, sp) + to);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return urlAtom(from + to);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
let abs = (f.auth ? f.auth + '@' : '') + (f.host ?? '');
|
|
171
|
+
if (to.startsWith('/')) {
|
|
172
|
+
abs += to;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
const path = f.pathname.replace(/\/[^/]*$/g, '');
|
|
176
|
+
abs += path + '/' + to;
|
|
177
|
+
}
|
|
178
|
+
if (f.protocol && (f.protocol !== 'file:') && !f.host) {
|
|
179
|
+
return urlAtom(f.protocol + abs);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
return urlAtom((f.protocol ? f.protocol + '//' : '') + abs);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function urlAtom(url) {
|
|
186
|
+
while (url.includes('/./')) {
|
|
187
|
+
url = url.replace(/\/\.\//g, '/');
|
|
188
|
+
}
|
|
189
|
+
while (/\/(?!\.\.)[^/]+\/\.\.\//.test(url)) {
|
|
190
|
+
url = url.replace(/\/(?!\.\.)[^/]+\/\.\.\//g, '/');
|
|
191
|
+
}
|
|
192
|
+
url = url.replace(/\.\.\//g, '');
|
|
193
|
+
return url;
|
|
194
|
+
}
|
|
195
|
+
exports.REGEXP_EMAIL = /^[-_\w.]+@[-_\w.]+\.([a-zA-Z]+)$/i;
|
|
196
|
+
function isEMail(email) {
|
|
197
|
+
return exports.REGEXP_EMAIL.test(email);
|
|
198
|
+
}
|
|
199
|
+
exports.REGEXP_IPV4 = /^[0-9]{1,3}(\.[0-9]{1,3}){3}$/i;
|
|
200
|
+
function isIPv4(ip) {
|
|
201
|
+
return exports.REGEXP_IPV4.test(ip);
|
|
202
|
+
}
|
|
203
|
+
exports.REGEXP_IPV6 = /^(\w*?:){2,7}[\w.]*$/i;
|
|
204
|
+
function isIPv6(ip) {
|
|
205
|
+
return exports.REGEXP_IPV6.test(ip + ':');
|
|
206
|
+
}
|
|
207
|
+
exports.REGEXP_DOMAIN = /^.+?\.((?![0-9]).)+$/i;
|
|
208
|
+
function isDomain(domain) {
|
|
209
|
+
return exports.REGEXP_DOMAIN.test(domain);
|
|
210
|
+
}
|
|
211
|
+
exports.REGEXP_ASCII = /^[\x20-\x7E]*$/;
|
|
212
|
+
function isAscii(text) {
|
|
213
|
+
return exports.REGEXP_ASCII.test(text);
|
|
214
|
+
}
|
|
215
|
+
function nlReplace(str, to = '\n') {
|
|
216
|
+
str = str.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
217
|
+
if (to !== '\n') {
|
|
218
|
+
str = str.replace(/\n/g, to);
|
|
219
|
+
}
|
|
220
|
+
return str;
|
|
221
|
+
}
|
|
222
|
+
let tldList;
|
|
223
|
+
async function parseDomain(domain) {
|
|
224
|
+
const rtn = {
|
|
225
|
+
tld: null,
|
|
226
|
+
sld: null,
|
|
227
|
+
domain: null,
|
|
228
|
+
sub: null
|
|
229
|
+
};
|
|
230
|
+
if (!isDomain(domain)) {
|
|
231
|
+
return rtn;
|
|
232
|
+
}
|
|
233
|
+
const arr = domain.split('.');
|
|
234
|
+
if (arr.length === 1) {
|
|
235
|
+
rtn.tld = arr[0].toLowerCase();
|
|
236
|
+
rtn.domain = rtn.tld;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
if (!tldList) {
|
|
240
|
+
tldList = JSON.parse(await fs.getContent(kebab.LIB_PATH + 'text/tld.json', 'utf8') ?? '[]');
|
|
241
|
+
}
|
|
242
|
+
const last2 = (arr[arr.length - 2] + '.' + arr[arr.length - 1]).toLowerCase();
|
|
243
|
+
if (tldList.includes(last2)) {
|
|
244
|
+
rtn.tld = last2;
|
|
245
|
+
if (arr.length === 2) {
|
|
246
|
+
rtn.domain = last2;
|
|
247
|
+
return rtn;
|
|
248
|
+
}
|
|
249
|
+
rtn.sld = arr[arr.length - 3].toLowerCase();
|
|
250
|
+
rtn.domain = rtn.sld + '.' + rtn.tld;
|
|
251
|
+
if (arr.length === 3) {
|
|
252
|
+
return rtn;
|
|
253
|
+
}
|
|
254
|
+
arr.splice(-3);
|
|
255
|
+
rtn.sub = arr.join('.').toLowerCase();
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
rtn.tld = arr[arr.length - 1].toLowerCase();
|
|
259
|
+
rtn.sld = arr[arr.length - 2].toLowerCase();
|
|
260
|
+
rtn.domain = rtn.sld + '.' + rtn.tld;
|
|
261
|
+
if (arr.length === 2) {
|
|
262
|
+
return rtn;
|
|
263
|
+
}
|
|
264
|
+
arr.splice(-2);
|
|
265
|
+
rtn.sub = arr.join('.').toLowerCase();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return rtn;
|
|
269
|
+
}
|
|
270
|
+
function match(str, regs) {
|
|
271
|
+
for (const reg of regs) {
|
|
272
|
+
if (reg.test(str)) {
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
function isPhoneCN(p) {
|
|
279
|
+
return /^1[0-9]{10}$/.test(p);
|
|
280
|
+
}
|
|
281
|
+
function isIdCardCN(idcard) {
|
|
282
|
+
if (idcard.length !== 18) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
const idcardBase = idcard.slice(0, 17);
|
|
286
|
+
const verifyCode = idcard.slice(17, 18);
|
|
287
|
+
const factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
|
|
288
|
+
const verifyCodeList = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
|
|
289
|
+
let total = BigInt(0);
|
|
290
|
+
for (let i = 0; i < 17; i++) {
|
|
291
|
+
total += BigInt(idcardBase.slice(i, i + 1)) * BigInt(factor[i]);
|
|
292
|
+
}
|
|
293
|
+
const mod = total % BigInt(11);
|
|
294
|
+
if (verifyCode === verifyCodeList[Number(mod)]) {
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function queryStringify(query, encode = true) {
|
|
302
|
+
if (encode) {
|
|
303
|
+
return Object.entries(query).map(([k, v]) => {
|
|
304
|
+
if (Array.isArray(v)) {
|
|
305
|
+
return v.map((i) => `${encodeURIComponent(k)}=${encodeURIComponent(i)}`).join('&');
|
|
306
|
+
}
|
|
307
|
+
return `${encodeURIComponent(k)}=${encodeURIComponent(v)}`;
|
|
308
|
+
}).join('&');
|
|
309
|
+
}
|
|
310
|
+
return Object.entries(query).map(([k, v]) => {
|
|
311
|
+
if (Array.isArray(v)) {
|
|
312
|
+
return v.map((i) => `${k}=${i}}`).join('&');
|
|
313
|
+
}
|
|
314
|
+
return `${k}=${v}`;
|
|
315
|
+
}).join('&');
|
|
316
|
+
}
|
|
317
|
+
function queryParse(query) {
|
|
318
|
+
const ret = {};
|
|
319
|
+
const arrayKeys = {};
|
|
320
|
+
const arr = query.split('&');
|
|
321
|
+
for (const i of arr) {
|
|
322
|
+
if (!i.length) {
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
const pos = i.indexOf('=');
|
|
326
|
+
const key = decodeURIComponent(pos === -1 ? i : i.slice(0, pos));
|
|
327
|
+
let value = '';
|
|
328
|
+
try {
|
|
329
|
+
value = pos === -1 ? '' : decodeURIComponent(i.slice(pos + 1));
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
value = pos === -1 ? '' : i.slice(pos + 1);
|
|
333
|
+
}
|
|
334
|
+
if (arrayKeys[key]) {
|
|
335
|
+
ret[key].push(value);
|
|
336
|
+
}
|
|
337
|
+
else if (undefined === ret[key]) {
|
|
338
|
+
ret[key] = value;
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
ret[key] = [ret[key], value];
|
|
342
|
+
arrayKeys[key] = true;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return ret;
|
|
346
|
+
}
|
|
347
|
+
function htmlescape(html) {
|
|
348
|
+
const type = typeof html;
|
|
349
|
+
if (type !== 'string') {
|
|
350
|
+
return '[' + type + ']';
|
|
351
|
+
}
|
|
352
|
+
return html.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, '"');
|
|
353
|
+
}
|
|
354
|
+
function isRealPath(path) {
|
|
355
|
+
path = path.replace(/\\/g, '/');
|
|
356
|
+
if (path.startsWith('/')) {
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
return /[a-z]+:/i.test(path.split('/')[0]) ? true : false;
|
|
360
|
+
}
|
|
361
|
+
function getFilename(path) {
|
|
362
|
+
path = path.replace(/\\/g, '/');
|
|
363
|
+
const lio = path.lastIndexOf('/');
|
|
364
|
+
if (lio === -1) {
|
|
365
|
+
return path;
|
|
366
|
+
}
|
|
367
|
+
return path.slice(lio + 1);
|
|
368
|
+
}
|
|
369
|
+
function stringifyResult(rtn) {
|
|
370
|
+
if (Array.isArray(rtn)) {
|
|
371
|
+
if (rtn.length === 0) {
|
|
372
|
+
return JSON.stringify({
|
|
373
|
+
'result': 0,
|
|
374
|
+
'msg': 'ERROR'
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
if (typeof rtn[0] === 'number') {
|
|
378
|
+
const json = { 'result': rtn[0] };
|
|
379
|
+
if (rtn[1] !== undefined) {
|
|
380
|
+
if (typeof rtn[1] === 'object') {
|
|
381
|
+
for (let i = 1; i < rtn.length; ++i) {
|
|
382
|
+
Object.assign(json, rtn[i]);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
json['msg'] = rtn[1];
|
|
387
|
+
for (let i = 2; i < rtn.length; ++i) {
|
|
388
|
+
Object.assign(json, rtn[i]);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return JSON.stringify(json);
|
|
393
|
+
}
|
|
394
|
+
return JSON.stringify(rtn);
|
|
395
|
+
}
|
|
396
|
+
return JSON.stringify(rtn);
|
|
397
|
+
}
|
|
398
|
+
function parseJson(str) {
|
|
399
|
+
try {
|
|
400
|
+
str = str.replace(/("[\w-]+?" *: *)([-+0-9]+)([ \r\n]*[,}]|$)/g, (v, v1, v2, v3) => {
|
|
401
|
+
return v1 + '"-mybigint-' + v2 + '"' + v3;
|
|
402
|
+
});
|
|
403
|
+
return JSON.parse(str, (k, v) => {
|
|
404
|
+
if (typeof v !== 'string') {
|
|
405
|
+
return v;
|
|
406
|
+
}
|
|
407
|
+
if (!v.startsWith('-mybigint-')) {
|
|
408
|
+
return v;
|
|
409
|
+
}
|
|
410
|
+
const ints = v.slice(10);
|
|
411
|
+
const int = parseInt(ints);
|
|
412
|
+
if (int <= Number.MAX_SAFE_INTEGER) {
|
|
413
|
+
return int;
|
|
414
|
+
}
|
|
415
|
+
return BigInt(ints);
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
catch {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function stringifyJson(obj, space) {
|
|
423
|
+
return JSON.stringify(obj, (k, v) => {
|
|
424
|
+
if (typeof v === 'bigint') {
|
|
425
|
+
return '-mybigint-' + v.toString();
|
|
426
|
+
}
|
|
427
|
+
return v;
|
|
428
|
+
}, space).replace(/"-mybigint-([-+0-9]+?)"/g, '$1');
|
|
429
|
+
}
|
|
430
|
+
function str2int(str, digits = 3) {
|
|
431
|
+
const num = parseFloat(str);
|
|
432
|
+
const factor = Math.pow(10, digits);
|
|
433
|
+
return Math.round(num * factor);
|
|
434
|
+
}
|
|
435
|
+
function int2str(int, digits = 4, decimal = 2) {
|
|
436
|
+
const sign = int < 0 ? '-' : '';
|
|
437
|
+
const absInt = Math.abs(int);
|
|
438
|
+
let intStr = absInt.toString();
|
|
439
|
+
while (intStr.length < digits + 1) {
|
|
440
|
+
intStr = '0' + intStr;
|
|
441
|
+
}
|
|
442
|
+
const intPart = intStr.slice(0, intStr.length - digits);
|
|
443
|
+
const decPart = intStr.slice(intStr.length - digits);
|
|
444
|
+
const decNum = parseInt(decPart);
|
|
445
|
+
const div = Math.pow(10, digits - decimal);
|
|
446
|
+
const round = Math.round(decNum / div);
|
|
447
|
+
const carry = Math.floor(round / Math.pow(10, decimal));
|
|
448
|
+
const newDecPart = round % Math.pow(10, decimal);
|
|
449
|
+
const intNum = parseInt(intPart, 10) + carry;
|
|
450
|
+
const decResult = newDecPart.toString().padStart(decimal, '0');
|
|
451
|
+
return `${sign}${intNum}${decResult ? `.${decResult}` : ''}`;
|
|
452
|
+
}
|