@maiyunnet/kebab 2.0.15 → 3.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/README.md +1 -5
- package/index.d.ts +1 -1
- package/index.js +16 -18
- package/lib/buffer.js +7 -20
- package/lib/captcha.js +6 -44
- package/lib/consistent.js +8 -51
- package/lib/core.d.ts +4 -4
- package/lib/core.js +70 -132
- package/lib/crypto.js +43 -99
- package/lib/db.d.ts +5 -5
- package/lib/db.js +31 -68
- package/lib/dns.d.ts +1 -1
- package/lib/dns.js +12 -50
- package/lib/fs.js +26 -81
- package/lib/jwt.d.ts +3 -3
- package/lib/jwt.js +9 -50
- package/lib/kv.d.ts +4 -4
- package/lib/kv.js +31 -69
- package/lib/lan.js +4 -41
- package/lib/net/cacert.pem +78 -2
- package/lib/net/formdata.js +5 -42
- package/lib/net/request.d.ts +2 -2
- package/lib/net/request.js +3 -42
- package/lib/net/response.d.ts +1 -1
- package/lib/net/response.js +1 -5
- package/lib/net.d.ts +5 -5
- package/lib/net.js +24 -73
- package/lib/s3.d.ts +1 -1
- package/lib/s3.js +23 -62
- package/lib/scan.d.ts +3 -3
- package/lib/scan.js +10 -50
- package/lib/session.d.ts +3 -3
- package/lib/session.js +9 -46
- package/lib/sql.d.ts +2 -2
- package/lib/sql.js +9 -50
- package/lib/ssh/sftp.js +5 -46
- package/lib/ssh/shell.js +2 -39
- package/lib/ssh.d.ts +2 -2
- package/lib/ssh.js +5 -43
- package/lib/text.d.ts +1 -1
- package/lib/text.js +40 -104
- package/lib/time.d.ts +1 -1
- package/lib/time.js +10 -50
- package/lib/turnstile.d.ts +1 -1
- package/lib/turnstile.js +6 -43
- package/lib/ws.d.ts +10 -2
- package/lib/ws.js +70 -53
- package/lib/zip.d.ts +1 -1
- package/lib/zip.js +10 -57
- package/lib/zlib.js +24 -89
- package/main.js +6 -44
- package/package.json +9 -8
- package/sys/child.js +10 -45
- package/sys/cmd.js +8 -43
- package/sys/ctr.d.ts +5 -5
- package/sys/ctr.js +11 -49
- package/sys/master.js +11 -46
- package/sys/mod.d.ts +9 -5
- package/sys/mod.js +28 -214
- package/sys/route.d.ts +2 -2
- package/sys/route.js +26 -64
- package/types/index.d.ts +1 -0
- package/www/example/ctr/main.d.ts +1 -1
- package/www/example/ctr/main.js +2 -38
- package/www/example/ctr/middle.d.ts +2 -2
- package/www/example/ctr/middle.js +2 -38
- package/www/example/ctr/test.d.ts +2 -2
- package/www/example/ctr/test.js +65 -72
- package/www/example/mod/test.d.ts +2 -2
- package/www/example/mod/test.js +4 -42
- package/www/example/mod/testdata.d.ts +1 -1
- package/www/example/mod/testdata.js +3 -8
- package/www/example/ws/mproxy.d.ts +1 -1
- package/www/example/ws/mproxy.js +6 -41
- package/www/example/ws/rproxy.d.ts +1 -1
- package/www/example/ws/rproxy.js +5 -40
- package/www/example/ws/rsocket.d.ts +4 -0
- package/www/example/ws/rsocket.js +12 -0
- package/www/example/ws/test.d.ts +6 -1
- package/www/example/ws/test.js +13 -42
- package/eslint.config.js +0 -22
package/lib/sql.js
CHANGED
|
@@ -1,57 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
4
3
|
* Date: 2019-5-27 20:18:50
|
|
5
4
|
* Last: 2020-3-29 19:37:25, 2022-07-24 22:38:11, 2023-5-24 18:49:18, 2023-6-13 22:20:21, 2023-12-11 13:58:54, 2023-12-14 13:14:40, 2023-12-21 00:04:40, 2024-4-11 19:29:29, 2024-9-2 17:15:28, 2025-8-3 21:28:18
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
-
var ownKeys = function(o) {
|
|
25
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
-
var ar = [];
|
|
27
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
-
return ar;
|
|
29
|
-
};
|
|
30
|
-
return ownKeys(o);
|
|
31
|
-
};
|
|
32
|
-
return function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
})();
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.Sql = void 0;
|
|
42
|
-
exports.get = get;
|
|
43
|
-
exports.format = format;
|
|
44
|
-
exports.aoMix = aoMix;
|
|
45
|
-
exports.column = column;
|
|
46
|
-
const lText = __importStar(require("~/lib/text"));
|
|
47
|
-
const lCore = __importStar(require("~/lib/core"));
|
|
6
|
+
import * as lText from '../lib/text.js';
|
|
7
|
+
import * as lCore from '../lib/core.js';
|
|
48
8
|
// --- 第三方 ---
|
|
49
|
-
|
|
9
|
+
import * as mysql2 from 'mysql2/promise';
|
|
50
10
|
// --- 库和定义 ---
|
|
51
|
-
|
|
11
|
+
import * as ctr from '../sys/ctr.js';
|
|
52
12
|
/** --- filed 用 token --- */
|
|
53
13
|
let columnToken = '';
|
|
54
|
-
class Sql {
|
|
14
|
+
export class Sql {
|
|
55
15
|
// --- 实例化 ---
|
|
56
16
|
constructor(pre, opt = {}) {
|
|
57
17
|
/** --- 前置 --- */
|
|
@@ -1018,13 +978,12 @@ class Sql {
|
|
|
1018
978
|
return true;
|
|
1019
979
|
}
|
|
1020
980
|
}
|
|
1021
|
-
exports.Sql = Sql;
|
|
1022
981
|
/**
|
|
1023
982
|
* --- 创建 sql 对象 ---
|
|
1024
983
|
* @param ctrPre ctr 对象或 pre 表前缀
|
|
1025
984
|
* @param opt 参数
|
|
1026
985
|
*/
|
|
1027
|
-
function get(ctrPre, opt = {}) {
|
|
986
|
+
export function get(ctrPre, opt = {}) {
|
|
1028
987
|
return new Sql(ctrPre instanceof ctr.Ctr ? ctrPre.getPrototype('_config').sql.pre : ctrPre, opt);
|
|
1029
988
|
}
|
|
1030
989
|
/**
|
|
@@ -1032,14 +991,14 @@ function get(ctrPre, opt = {}) {
|
|
|
1032
991
|
* @param sql SQL 字符串
|
|
1033
992
|
* @param data DATA 数据
|
|
1034
993
|
*/
|
|
1035
|
-
function format(sql, data) {
|
|
994
|
+
export function format(sql, data) {
|
|
1036
995
|
return mysql2.format(sql, data);
|
|
1037
996
|
}
|
|
1038
997
|
/**
|
|
1039
998
|
* --- 将数组兑换为组合的对象(Array/Object mix) ---
|
|
1040
999
|
* @param arr 要转换的数组
|
|
1041
1000
|
*/
|
|
1042
|
-
function aoMix(arr) {
|
|
1001
|
+
export function aoMix(arr) {
|
|
1043
1002
|
if (!Array.isArray(arr)) {
|
|
1044
1003
|
return arr;
|
|
1045
1004
|
}
|
|
@@ -1059,7 +1018,7 @@ function aoMix(arr) {
|
|
|
1059
1018
|
return mix;
|
|
1060
1019
|
}
|
|
1061
1020
|
/** --- 创建字段对象 --- */
|
|
1062
|
-
function column(field) {
|
|
1021
|
+
export function column(field) {
|
|
1063
1022
|
if (!columnToken) {
|
|
1064
1023
|
columnToken = lCore.random(8, lCore.RANDOM_LUNS);
|
|
1065
1024
|
}
|
package/lib/ssh/sftp.js
CHANGED
|
@@ -1,43 +1,7 @@
|
|
|
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.Connection = void 0;
|
|
37
1
|
// --- 库和定义 ---
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class Connection {
|
|
2
|
+
import * as core from '../../lib/core.js';
|
|
3
|
+
import * as text from '../../lib/text.js';
|
|
4
|
+
export class Connection {
|
|
41
5
|
constructor(sftp, path) {
|
|
42
6
|
this._client = sftp;
|
|
43
7
|
this._path = path;
|
|
@@ -54,9 +18,7 @@ class Connection {
|
|
|
54
18
|
'encoding': options
|
|
55
19
|
};
|
|
56
20
|
}
|
|
57
|
-
|
|
58
|
-
options = {};
|
|
59
|
-
}
|
|
21
|
+
options ??= {};
|
|
60
22
|
const encoding = options.encoding;
|
|
61
23
|
const start = options.start;
|
|
62
24
|
const end = options.end;
|
|
@@ -407,9 +369,7 @@ class Connection {
|
|
|
407
369
|
'encoding': options
|
|
408
370
|
};
|
|
409
371
|
}
|
|
410
|
-
|
|
411
|
-
options = {};
|
|
412
|
-
}
|
|
372
|
+
options ??= {};
|
|
413
373
|
return this._client.createWriteStream(path, options);
|
|
414
374
|
}
|
|
415
375
|
/**
|
|
@@ -476,4 +436,3 @@ class Connection {
|
|
|
476
436
|
this._client.end();
|
|
477
437
|
}
|
|
478
438
|
}
|
|
479
|
-
exports.Connection = Connection;
|
package/lib/ssh/shell.js
CHANGED
|
@@ -1,41 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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.Connection = void 0;
|
|
37
|
-
const lCore = __importStar(require("~/lib/core"));
|
|
38
|
-
class Connection {
|
|
1
|
+
import * as lCore from '../../lib/core.js';
|
|
2
|
+
export class Connection {
|
|
39
3
|
constructor(stream) {
|
|
40
4
|
this._client = stream;
|
|
41
5
|
}
|
|
@@ -137,4 +101,3 @@ class Connection {
|
|
|
137
101
|
return this._client;
|
|
138
102
|
}
|
|
139
103
|
}
|
|
140
|
-
exports.Connection = Connection;
|
package/lib/ssh.d.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Last: 2020-04-06 21:22:46, 2022-09-12 00:19:05, 2024-3-4 14:46:11
|
|
5
5
|
*/
|
|
6
6
|
import * as ssh2 from 'ssh2';
|
|
7
|
-
import * as shell from './ssh/shell';
|
|
8
|
-
import * as sftp from './ssh/sftp';
|
|
7
|
+
import * as shell from './ssh/shell.js';
|
|
8
|
+
import * as sftp from './ssh/sftp.js';
|
|
9
9
|
interface IExtOptions {
|
|
10
10
|
'mproxy'?: {
|
|
11
11
|
'host': string;
|
package/lib/ssh.js
CHANGED
|
@@ -1,52 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
4
3
|
* Date: 2019-6-8 21:34:35
|
|
5
4
|
* Last: 2020-04-06 21:22:46, 2022-09-12 00:19:05, 2024-3-4 14:46:11
|
|
6
5
|
*/
|
|
7
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
-
if (k2 === undefined) k2 = k;
|
|
9
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
-
}
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
-
var ownKeys = function(o) {
|
|
25
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
-
var ar = [];
|
|
27
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
-
return ar;
|
|
29
|
-
};
|
|
30
|
-
return ownKeys(o);
|
|
31
|
-
};
|
|
32
|
-
return function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
})();
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.Connection = void 0;
|
|
42
|
-
exports.get = get;
|
|
43
6
|
// --- 第三方 ---
|
|
44
|
-
|
|
7
|
+
import * as ssh2 from 'ssh2';
|
|
45
8
|
// --- 自己 ---
|
|
46
|
-
|
|
47
|
-
|
|
9
|
+
import * as shell from './ssh/shell.js';
|
|
10
|
+
import * as sftp from './ssh/sftp.js';
|
|
48
11
|
/** 主连接对象 */
|
|
49
|
-
class Connection {
|
|
12
|
+
export class Connection {
|
|
50
13
|
constructor() {
|
|
51
14
|
this._client = new ssh2.Client();
|
|
52
15
|
}
|
|
@@ -191,12 +154,11 @@ class Connection {
|
|
|
191
154
|
});
|
|
192
155
|
}
|
|
193
156
|
}
|
|
194
|
-
exports.Connection = Connection;
|
|
195
157
|
/**
|
|
196
158
|
* --- 创建一个 SSH 连接 ---
|
|
197
159
|
* @param opt 选项
|
|
198
160
|
*/
|
|
199
|
-
async function get(opt) {
|
|
161
|
+
export async function get(opt) {
|
|
200
162
|
const conn = new Connection();
|
|
201
163
|
const rtn = await conn.connect(opt);
|
|
202
164
|
return rtn ? conn : null;
|
package/lib/text.d.ts
CHANGED
package/lib/text.js
CHANGED
|
@@ -1,80 +1,16 @@
|
|
|
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.stringifyBuffer = stringifyBuffer;
|
|
60
|
-
exports.isFalsy = isFalsy;
|
|
61
|
-
exports.isTruthy = isTruthy;
|
|
62
|
-
exports.logicalOr = logicalOr;
|
|
63
|
-
exports.str2int = str2int;
|
|
64
|
-
exports.int2str = int2str;
|
|
65
1
|
/**
|
|
66
2
|
* Project: Kebab, User: JianSuoQiYue
|
|
67
3
|
* Date: 2019-5-15 16:49:39
|
|
68
4
|
* Last: 2020-04-06 20:51:06, 2022-9-29 15:18:16, 2022-12-29 00:01:30, 2024-3-6 17:53:14, 2024-5-31 17:29:52, 2025-6-13 15:47:02
|
|
69
5
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
6
|
+
import * as kebab from '../index.js';
|
|
7
|
+
import * as fs from './fs.js';
|
|
72
8
|
/**
|
|
73
9
|
* --- 将文件大小格式化为带单位的字符串 ---
|
|
74
10
|
* @param size 文件大小
|
|
75
11
|
* @param spliter 分隔符
|
|
76
12
|
*/
|
|
77
|
-
function sizeFormat(size, spliter = ' ') {
|
|
13
|
+
export function sizeFormat(size, spliter = ' ') {
|
|
78
14
|
const units = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
|
79
15
|
let i = 0;
|
|
80
16
|
for (; i < 6 && size >= 1024.0; ++i) {
|
|
@@ -86,7 +22,7 @@ function sizeFormat(size, spliter = ' ') {
|
|
|
86
22
|
* --- 格式化一段 URL ---
|
|
87
23
|
* @param url
|
|
88
24
|
*/
|
|
89
|
-
function parseUrl(url) {
|
|
25
|
+
export function parseUrl(url) {
|
|
90
26
|
// --- test: https://ab-3dc:aak9()$@github.com:80/nodejs/node/blob/master/lib/url.js?mail=abc@def.com#223 ---
|
|
91
27
|
const rtn = {
|
|
92
28
|
'protocol': null,
|
|
@@ -168,7 +104,7 @@ function parseUrl(url) {
|
|
|
168
104
|
* @param from 基准路径
|
|
169
105
|
* @param to 相对路径
|
|
170
106
|
*/
|
|
171
|
-
function urlResolve(from, to) {
|
|
107
|
+
export function urlResolve(from, to) {
|
|
172
108
|
from = from.replace('\\', '/');
|
|
173
109
|
to = to.replace('\\', '/');
|
|
174
110
|
// --- to 为空,直接返回 form ---
|
|
@@ -229,7 +165,7 @@ function urlResolve(from, to) {
|
|
|
229
165
|
* --- 将路径中的 ../ ./ 都按规范妥善处理 ---
|
|
230
166
|
* @param url 要处理的地址
|
|
231
167
|
*/
|
|
232
|
-
function urlAtom(url) {
|
|
168
|
+
export function urlAtom(url) {
|
|
233
169
|
// --- 删掉 ./ ---
|
|
234
170
|
while (url.includes('/./')) {
|
|
235
171
|
url = url.replace(/\/\.\//g, '/');
|
|
@@ -241,53 +177,53 @@ function urlAtom(url) {
|
|
|
241
177
|
url = url.replace(/\.\.\//g, '');
|
|
242
178
|
return url;
|
|
243
179
|
}
|
|
244
|
-
|
|
180
|
+
export const REGEXP_EMAIL = /^[-_\w.]+@[-_\w.]+\.([a-zA-Z]+)$/i;
|
|
245
181
|
/**
|
|
246
182
|
* --- 是否是邮件地址 ---
|
|
247
183
|
* @param email
|
|
248
184
|
*/
|
|
249
|
-
function isEMail(email) {
|
|
250
|
-
return
|
|
185
|
+
export function isEMail(email) {
|
|
186
|
+
return REGEXP_EMAIL.test(email);
|
|
251
187
|
}
|
|
252
|
-
|
|
188
|
+
export const REGEXP_IPV4 = /^[0-9]{1,3}(\.[0-9]{1,3}){3}$/i;
|
|
253
189
|
/**
|
|
254
190
|
* --- 是否是 IPv4 ---
|
|
255
191
|
* @param ip
|
|
256
192
|
*/
|
|
257
|
-
function isIPv4(ip) {
|
|
258
|
-
return
|
|
193
|
+
export function isIPv4(ip) {
|
|
194
|
+
return REGEXP_IPV4.test(ip);
|
|
259
195
|
}
|
|
260
|
-
|
|
196
|
+
export const REGEXP_IPV6 = /^(\w*?:){2,7}[\w.]*$/i;
|
|
261
197
|
/**
|
|
262
198
|
* --- 是否是 IPv6 ---
|
|
263
199
|
* @param ip
|
|
264
200
|
*/
|
|
265
|
-
function isIPv6(ip) {
|
|
266
|
-
return
|
|
201
|
+
export function isIPv6(ip) {
|
|
202
|
+
return REGEXP_IPV6.test(ip + ':');
|
|
267
203
|
}
|
|
268
|
-
|
|
204
|
+
export const REGEXP_DOMAIN = /^.+?\.((?![0-9]).)+$/i;
|
|
269
205
|
/**
|
|
270
206
|
* --- 判断是否是域名 ---
|
|
271
207
|
* @param string $domain
|
|
272
208
|
* @return bool
|
|
273
209
|
*/
|
|
274
|
-
function isDomain(domain) {
|
|
275
|
-
return
|
|
210
|
+
export function isDomain(domain) {
|
|
211
|
+
return REGEXP_DOMAIN.test(domain);
|
|
276
212
|
}
|
|
277
|
-
|
|
213
|
+
export const REGEXP_ASCII = /^[\x20-\x7E]*$/;
|
|
278
214
|
/**
|
|
279
215
|
* --- 判断是否在 ascii 字符集内,仅可输入部分 ---
|
|
280
216
|
* @param text 要判断的文本
|
|
281
217
|
*/
|
|
282
|
-
function isAscii(text) {
|
|
283
|
-
return
|
|
218
|
+
export function isAscii(text) {
|
|
219
|
+
return REGEXP_ASCII.test(text);
|
|
284
220
|
}
|
|
285
221
|
/**
|
|
286
222
|
* --- 换行替换为别的 ---
|
|
287
223
|
* @param str 要替换的字符串
|
|
288
224
|
* @param to 换行替换符
|
|
289
225
|
*/
|
|
290
|
-
function nlReplace(str, to = '\n') {
|
|
226
|
+
export function nlReplace(str, to = '\n') {
|
|
291
227
|
str = str.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
292
228
|
if (to !== '\n') {
|
|
293
229
|
str = str.replace(/\n/g, to);
|
|
@@ -300,7 +236,7 @@ let tldList;
|
|
|
300
236
|
* --- 解析域名并获取 tld/sld/domain/sub ---
|
|
301
237
|
* @param domain 域名
|
|
302
238
|
*/
|
|
303
|
-
async function parseDomain(domain) {
|
|
239
|
+
export async function parseDomain(domain) {
|
|
304
240
|
const rtn = {
|
|
305
241
|
tld: null,
|
|
306
242
|
sld: null,
|
|
@@ -356,7 +292,7 @@ async function parseDomain(domain) {
|
|
|
356
292
|
* @param str 要检测的字符串
|
|
357
293
|
* @param regs 正则列表
|
|
358
294
|
*/
|
|
359
|
-
function match(str, regs) {
|
|
295
|
+
export function match(str, regs) {
|
|
360
296
|
for (const reg of regs) {
|
|
361
297
|
if (reg.test(str)) {
|
|
362
298
|
return true;
|
|
@@ -369,14 +305,14 @@ function match(str, regs) {
|
|
|
369
305
|
* --- 判断手机号是否是 11 位,不做真实性校验 ---
|
|
370
306
|
* @param p 手机号
|
|
371
307
|
*/
|
|
372
|
-
function isPhoneCN(p) {
|
|
308
|
+
export function isPhoneCN(p) {
|
|
373
309
|
return /^1[0-9]{10}$/.test(p);
|
|
374
310
|
}
|
|
375
311
|
/**
|
|
376
312
|
* --- 是否是中国大陆身份证号码 ---
|
|
377
313
|
* @param idcard 身份证号
|
|
378
314
|
*/
|
|
379
|
-
function isIdCardCN(idcard) {
|
|
315
|
+
export function isIdCardCN(idcard) {
|
|
380
316
|
if (idcard.length !== 18) {
|
|
381
317
|
return false;
|
|
382
318
|
}
|
|
@@ -409,7 +345,7 @@ function isIdCardCN(idcard) {
|
|
|
409
345
|
* @param query 要转换的对象
|
|
410
346
|
* @param encode 是否转义
|
|
411
347
|
*/
|
|
412
|
-
function queryStringify(query, encode = true) {
|
|
348
|
+
export function queryStringify(query, encode = true) {
|
|
413
349
|
if (encode) {
|
|
414
350
|
return Object.entries(query).map(([k, v]) => {
|
|
415
351
|
if (Array.isArray(v)) {
|
|
@@ -429,7 +365,7 @@ function queryStringify(query, encode = true) {
|
|
|
429
365
|
* --- 将 query string 转换为对象 ---
|
|
430
366
|
* @param query 要转换的字符串
|
|
431
367
|
*/
|
|
432
|
-
function queryParse(query) {
|
|
368
|
+
export function queryParse(query) {
|
|
433
369
|
const ret = {};
|
|
434
370
|
const arrayKeys = {};
|
|
435
371
|
const arr = query.split('&');
|
|
@@ -463,7 +399,7 @@ function queryParse(query) {
|
|
|
463
399
|
* --- HTML 特殊字符转换为实体字符 ---
|
|
464
400
|
* @param html 待转换的 HTML
|
|
465
401
|
*/
|
|
466
|
-
function htmlescape(html) {
|
|
402
|
+
export function htmlescape(html) {
|
|
467
403
|
const type = typeof html;
|
|
468
404
|
if (type !== 'string') {
|
|
469
405
|
return '[' + type + ']';
|
|
@@ -474,7 +410,7 @@ function htmlescape(html) {
|
|
|
474
410
|
* --- 判断是否是绝对路径,是返回 true,相对路径返回 false ---
|
|
475
411
|
* @param path 要判断的路径字符串
|
|
476
412
|
*/
|
|
477
|
-
function isRealPath(path) {
|
|
413
|
+
export function isRealPath(path) {
|
|
478
414
|
path = path.replace(/\\/g, '/');
|
|
479
415
|
if (path.startsWith('/')) {
|
|
480
416
|
return true;
|
|
@@ -485,7 +421,7 @@ function isRealPath(path) {
|
|
|
485
421
|
* --- 获取文件名 ---
|
|
486
422
|
* @param path 文件路径
|
|
487
423
|
*/
|
|
488
|
-
function getFilename(path) {
|
|
424
|
+
export function getFilename(path) {
|
|
489
425
|
path = path.replace(/\\/g, '/');
|
|
490
426
|
const lio = path.lastIndexOf('/');
|
|
491
427
|
if (lio === -1) {
|
|
@@ -497,7 +433,7 @@ function getFilename(path) {
|
|
|
497
433
|
* --- 将普通的返回 JSON 对象序列化为字符串,Mutton 不能使用 ---
|
|
498
434
|
* @param o 返回 JSON 对象
|
|
499
435
|
*/
|
|
500
|
-
function stringifyResult(rtn) {
|
|
436
|
+
export function stringifyResult(rtn) {
|
|
501
437
|
if (Array.isArray(rtn)) {
|
|
502
438
|
// --- [0, 'xxx'] 模式 ---
|
|
503
439
|
if (rtn.length === 0) {
|
|
@@ -536,7 +472,7 @@ function stringifyResult(rtn) {
|
|
|
536
472
|
* --- 将字符串解析为对象,返回 false 代表解析失败,支持 BigInt,Kebab true, Mutton false ---
|
|
537
473
|
* @param str 要解析的 json 字符串
|
|
538
474
|
*/
|
|
539
|
-
function parseJson(str) {
|
|
475
|
+
export function parseJson(str) {
|
|
540
476
|
try {
|
|
541
477
|
str = str.replace(/("[\w-]+?" *: *)([-+0-9]+)([ \r\n]*[,}]|$)/g, (v, v1, v2, v3) => {
|
|
542
478
|
return v1 + '"-mybigint-' + v2 + '"' + v3;
|
|
@@ -565,7 +501,7 @@ function parseJson(str) {
|
|
|
565
501
|
* @param obj 要转换的 json 对象
|
|
566
502
|
* @param space 美化方式
|
|
567
503
|
*/
|
|
568
|
-
function stringifyJson(obj, space) {
|
|
504
|
+
export function stringifyJson(obj, space) {
|
|
569
505
|
return JSON.stringify(obj, (k, v) => {
|
|
570
506
|
if (typeof v === 'bigint') {
|
|
571
507
|
return '-mybigint-' + v.toString();
|
|
@@ -577,7 +513,7 @@ function stringifyJson(obj, space) {
|
|
|
577
513
|
* --- 输出文本格式的 buffer ---
|
|
578
514
|
* @param buf 原始 buffer
|
|
579
515
|
*/
|
|
580
|
-
function stringifyBuffer(buf) {
|
|
516
|
+
export function stringifyBuffer(buf) {
|
|
581
517
|
const arr = buf.toString('hex').match(/.{1,2}/g);
|
|
582
518
|
return `<Buffer ${arr ? arr.join(' ') : ''}>`;
|
|
583
519
|
}
|
|
@@ -585,14 +521,14 @@ function stringifyBuffer(buf) {
|
|
|
585
521
|
* --- 判断一个值是否是虚假的(为 null/undefined/空字符串/false/0) ---
|
|
586
522
|
* @param val 要判断的值
|
|
587
523
|
*/
|
|
588
|
-
function isFalsy(val) {
|
|
524
|
+
export function isFalsy(val) {
|
|
589
525
|
return (val === null) || (val === undefined) || (val === '') || (val === false) || (val === 0);
|
|
590
526
|
}
|
|
591
527
|
/**
|
|
592
528
|
* --- 判断一个值是否是真实的(不为 null/undefined/空字符串/false/0) ---
|
|
593
529
|
* @param val 要判断的值
|
|
594
530
|
*/
|
|
595
|
-
function isTruthy(val) {
|
|
531
|
+
export function isTruthy(val) {
|
|
596
532
|
return !isFalsy(val);
|
|
597
533
|
}
|
|
598
534
|
/**
|
|
@@ -600,7 +536,7 @@ function isTruthy(val) {
|
|
|
600
536
|
* @param v1 比对值
|
|
601
537
|
* @param v2 比对值
|
|
602
538
|
*/
|
|
603
|
-
function logicalOr(v1, v2) {
|
|
539
|
+
export function logicalOr(v1, v2) {
|
|
604
540
|
return (isFalsy(v1) ? v2 : v1);
|
|
605
541
|
}
|
|
606
542
|
/**
|
|
@@ -613,7 +549,7 @@ function logicalOr(v1, v2) {
|
|
|
613
549
|
* @param str 要转换的数字字符串
|
|
614
550
|
* @param digits 小数点右移位数
|
|
615
551
|
*/
|
|
616
|
-
function str2int(str, digits = 3) {
|
|
552
|
+
export function str2int(str, digits = 3) {
|
|
617
553
|
const num = parseFloat(str);
|
|
618
554
|
/** --- 位数,如 1000 --- */
|
|
619
555
|
const factor = Math.pow(10, digits);
|
|
@@ -630,7 +566,7 @@ function str2int(str, digits = 3) {
|
|
|
630
566
|
* @param digits 小数点左移位数
|
|
631
567
|
* @param decimal 最终保留的小数位数
|
|
632
568
|
*/
|
|
633
|
-
function int2str(int, digits = 4, decimal = 2) {
|
|
569
|
+
export function int2str(int, digits = 4, decimal = 2) {
|
|
634
570
|
/** --- 正负符号 --- */
|
|
635
571
|
const sign = int < 0 ? '-' : '';
|
|
636
572
|
const absInt = Math.abs(int);
|
package/lib/time.d.ts
CHANGED