@maiyunnet/kebab 9.22.4 → 9.22.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/abox/master-log.d.ts +1 -0
- package/abox/master-log.js +26 -0
- package/abox/text.d.ts +2 -0
- package/abox/text.js +21 -0
- package/doc/kebab-rag.md +127 -103
- package/index.d.ts +7 -2
- package/index.js +1 -1
- package/lib/text.d.ts +6 -4
- package/lib/text.js +11 -34
- package/package.json +3 -2
- package/sys/master.js +185 -279
- package/sys/route.d.ts +5 -5
- package/sys/route.js +33 -20
package/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
6
6
|
*/
|
|
7
7
|
/** --- 当前系统版本号 --- */
|
|
8
|
-
export declare const VER = "9.22.
|
|
8
|
+
export declare const VER = "9.22.5";
|
|
9
9
|
/** --- 框架根目录,以 / 结尾 --- */
|
|
10
10
|
export declare const ROOT_PATH: string;
|
|
11
11
|
/** --- 框架的 LIB,以 / 结尾 --- */
|
|
@@ -156,10 +156,15 @@ export interface IConfigConst {
|
|
|
156
156
|
'wechat': boolean;
|
|
157
157
|
'miniprogram': '' | 'wechat';
|
|
158
158
|
'https': boolean;
|
|
159
|
+
/** --- 原始主机地址,保留端口 --- */
|
|
159
160
|
'host': string;
|
|
161
|
+
/** --- 主机名,不含端口或 IPv6 方括号 --- */
|
|
160
162
|
'hostname': string;
|
|
163
|
+
/** --- 请求端口 --- */
|
|
161
164
|
'hostport': number;
|
|
162
|
-
/** ---
|
|
165
|
+
/** --- 用于 URL 的主机地址,仅省略 HTTPS 的 443 和 HTTP 的 80 端口,保留 IPv6 方括号 --- */
|
|
166
|
+
'hostCanonical': string;
|
|
167
|
+
/** --- 协议与 hostCanonical,如 https://example.com:8443 --- */
|
|
163
168
|
'urlOrigin': string;
|
|
164
169
|
'uri': IUrlParse;
|
|
165
170
|
'rootPath': string;
|
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '9.22.
|
|
9
|
+
export const VER = '9.22.5';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/lib/text.d.ts
CHANGED
|
@@ -57,12 +57,12 @@ export declare const REGEXP_EMAIL: RegExp;
|
|
|
57
57
|
*/
|
|
58
58
|
export declare function isEMail(email: string): boolean;
|
|
59
59
|
/**
|
|
60
|
-
* --- 是否是 IPv4(基于 Node 原生 net.
|
|
60
|
+
* --- 是否是 IPv4(基于 Node 原生 net.isIPv4,严格校验) ---
|
|
61
61
|
* @param ip
|
|
62
62
|
*/
|
|
63
63
|
export declare function isIPv4(ip: string): boolean;
|
|
64
64
|
/**
|
|
65
|
-
* --- 是否是 IPv6(基于 Node 原生 net.
|
|
65
|
+
* --- 是否是 IPv6(基于 Node 原生 net.isIPv6,严格校验) ---
|
|
66
66
|
* @param ip
|
|
67
67
|
*/
|
|
68
68
|
export declare function isIPv6(ip: string): boolean;
|
|
@@ -173,14 +173,16 @@ export declare function getFileNameExt(path: string): {
|
|
|
173
173
|
*/
|
|
174
174
|
export declare function stringifyResult(rtn: kebab.Json): string;
|
|
175
175
|
/**
|
|
176
|
-
* ---
|
|
176
|
+
* --- 解析 JSON,超出安全整数范围的整数字面量转换为 BigInt ---
|
|
177
177
|
* @param str 要解析的 json 字符串
|
|
178
|
+
* @returns 解析结果,无效 JSON 返回 false;小数及指数形式仍为 number
|
|
178
179
|
*/
|
|
179
180
|
export declare function parseJson<T>(str: string): T | false;
|
|
180
181
|
/**
|
|
181
|
-
* --- 将对象转换为
|
|
182
|
+
* --- 将对象转换为 JSON 字符串,BigInt 输出为整数字面量 ---
|
|
182
183
|
* @param obj 要转换的 json 对象
|
|
183
184
|
* @param space 美化方式
|
|
185
|
+
* @returns JSON 字符串,循环引用等序列化错误沿用 JSON.stringify 异常
|
|
184
186
|
*/
|
|
185
187
|
export declare function stringifyJson(obj: kebab.Json, space?: string | number): string;
|
|
186
188
|
/**
|
package/lib/text.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
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, 2025-9-23 12:51:49, 2026-8-22
|
|
5
5
|
*/
|
|
6
6
|
import * as net from 'net';
|
|
7
|
+
import * as textJson from '#kebab/abox/text.js';
|
|
7
8
|
import * as kebab from '#kebab/index.js';
|
|
8
9
|
import * as lFs from './fs.js';
|
|
9
10
|
import * as lCore from './core.js';
|
|
@@ -275,18 +276,18 @@ export function isEMail(email) {
|
|
|
275
276
|
return REGEXP_EMAIL.test(email);
|
|
276
277
|
}
|
|
277
278
|
/**
|
|
278
|
-
* --- 是否是 IPv4(基于 Node 原生 net.
|
|
279
|
+
* --- 是否是 IPv4(基于 Node 原生 net.isIPv4,严格校验) ---
|
|
279
280
|
* @param ip
|
|
280
281
|
*/
|
|
281
282
|
export function isIPv4(ip) {
|
|
282
|
-
return net.
|
|
283
|
+
return net.isIPv4(ip);
|
|
283
284
|
}
|
|
284
285
|
/**
|
|
285
|
-
* --- 是否是 IPv6(基于 Node 原生 net.
|
|
286
|
+
* --- 是否是 IPv6(基于 Node 原生 net.isIPv6,严格校验) ---
|
|
286
287
|
* @param ip
|
|
287
288
|
*/
|
|
288
289
|
export function isIPv6(ip) {
|
|
289
|
-
return net.
|
|
290
|
+
return net.isIPv6(ip);
|
|
290
291
|
}
|
|
291
292
|
export const REGEXP_DOMAIN = /^.+?\.((?![0-9]).)+$/i;
|
|
292
293
|
/**
|
|
@@ -620,45 +621,21 @@ export function stringifyResult(rtn) {
|
|
|
620
621
|
return JSON.stringify(rtn);
|
|
621
622
|
}
|
|
622
623
|
/**
|
|
623
|
-
* ---
|
|
624
|
+
* --- 解析 JSON,超出安全整数范围的整数字面量转换为 BigInt ---
|
|
624
625
|
* @param str 要解析的 json 字符串
|
|
626
|
+
* @returns 解析结果,无效 JSON 返回 false;小数及指数形式仍为 number
|
|
625
627
|
*/
|
|
626
628
|
export function parseJson(str) {
|
|
627
|
-
|
|
628
|
-
str = str.replace(/("[\w-]+?" *: *)([-+0-9]+)([ \r\n]*[,}]|$)/g, (v, v1, v2, v3) => {
|
|
629
|
-
return v1 + '"-mybigint-' + v2 + '"' + v3;
|
|
630
|
-
});
|
|
631
|
-
return JSON.parse(str, (k, v) => {
|
|
632
|
-
if (typeof v !== 'string') {
|
|
633
|
-
return v;
|
|
634
|
-
}
|
|
635
|
-
if (!v.startsWith('-mybigint-')) {
|
|
636
|
-
return v;
|
|
637
|
-
}
|
|
638
|
-
const ints = v.slice(10);
|
|
639
|
-
const int = parseInt(ints);
|
|
640
|
-
if ((int >= Number.MIN_SAFE_INTEGER) && (int <= Number.MAX_SAFE_INTEGER)) {
|
|
641
|
-
return int;
|
|
642
|
-
}
|
|
643
|
-
return BigInt(ints);
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
catch {
|
|
647
|
-
return false;
|
|
648
|
-
}
|
|
629
|
+
return textJson.parseJson(str);
|
|
649
630
|
}
|
|
650
631
|
/**
|
|
651
|
-
* --- 将对象转换为
|
|
632
|
+
* --- 将对象转换为 JSON 字符串,BigInt 输出为整数字面量 ---
|
|
652
633
|
* @param obj 要转换的 json 对象
|
|
653
634
|
* @param space 美化方式
|
|
635
|
+
* @returns JSON 字符串,循环引用等序列化错误沿用 JSON.stringify 异常
|
|
654
636
|
*/
|
|
655
637
|
export function stringifyJson(obj, space) {
|
|
656
|
-
return
|
|
657
|
-
if (typeof v === 'bigint') {
|
|
658
|
-
return '-mybigint-' + v.toString();
|
|
659
|
-
}
|
|
660
|
-
return v;
|
|
661
|
-
}, space).replace(/"-mybigint-([-+0-9]+?)"/g, '$1');
|
|
638
|
+
return textJson.stringifyJson(obj, space);
|
|
662
639
|
}
|
|
663
640
|
/**
|
|
664
641
|
* --- 将未知异常转换为适合单行日志的文本,Error 优先返回完整堆栈 ---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maiyunnet/kebab",
|
|
3
|
-
"version": "9.22.
|
|
3
|
+
"version": "9.22.5",
|
|
4
4
|
"description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build-doc": "bash ./utils/build-doc.sh",
|
|
17
17
|
"test:formdata": "node abox/test/formdata.mjs",
|
|
18
|
-
"test:rpc": "node --test --test-isolation=none abox/test/rpc.mjs"
|
|
18
|
+
"test:rpc": "node --test --test-isolation=none abox/test/rpc.mjs",
|
|
19
|
+
"test:master": "node --test --test-isolation=none abox/test/master.mjs"
|
|
19
20
|
},
|
|
20
21
|
"bin": {
|
|
21
22
|
"kebab": "./bin/kebab.js"
|