@maiyunnet/kebab 9.22.3 → 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 +179 -155
- package/index.d.ts +7 -2
- package/index.js +1 -1
- package/lib/core.js +69 -139
- package/lib/text.d.ts +6 -4
- package/lib/text.js +11 -34
- package/package.json +4 -2
- package/sys/master.js +193 -283
- 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/core.js
CHANGED
|
@@ -638,31 +638,22 @@ export async function sendReload(hosts) {
|
|
|
638
638
|
if (!hosts?.length) {
|
|
639
639
|
hosts = ['127.0.0.1'];
|
|
640
640
|
}
|
|
641
|
-
|
|
642
|
-
const
|
|
643
|
-
/** --- 返回成功的 host --- */
|
|
644
|
-
const rtn = {};
|
|
645
|
-
for (const host of hosts) {
|
|
641
|
+
/** --- 并行发送,各主机独立等待,结果保持输入顺序 --- */
|
|
642
|
+
const results = await Promise.all(hosts.map(async (host) => {
|
|
646
643
|
const res = await lUndici.get('http://' + host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
|
|
647
644
|
'action': 'reload',
|
|
648
|
-
'time':
|
|
645
|
+
'time': lTime.stamp()
|
|
649
646
|
}), globalConfig.rpcSecret), {
|
|
650
647
|
'timeout': 5
|
|
651
648
|
});
|
|
652
649
|
const content = await res.getContent();
|
|
653
650
|
if (!content) {
|
|
654
|
-
|
|
655
|
-
continue;
|
|
651
|
+
return [host, { 'result': false, 'return': 'Timeout' }];
|
|
656
652
|
}
|
|
657
653
|
const str = content.toString();
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
else {
|
|
662
|
-
rtn[host] = { 'result': false, 'return': str };
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
return rtn;
|
|
654
|
+
return [host, { 'result': str === 'Done', 'return': str }];
|
|
655
|
+
}));
|
|
656
|
+
return Object.fromEntries(results);
|
|
666
657
|
}
|
|
667
658
|
/**
|
|
668
659
|
* --- 向主进程(或局域网同代码机子)发送广播将进行 restart 操作,停止监听并启动新进程,老进程在连接全部断开后自行销毁 ---
|
|
@@ -687,31 +678,22 @@ export async function sendRestart(hosts) {
|
|
|
687
678
|
if (!hosts?.length) {
|
|
688
679
|
hosts = ['127.0.0.1'];
|
|
689
680
|
}
|
|
690
|
-
|
|
691
|
-
const
|
|
692
|
-
/** --- 返回成功的 host --- */
|
|
693
|
-
const rtn = {};
|
|
694
|
-
for (const host of hosts) {
|
|
681
|
+
/** --- 并行发送,各主机独立等待,结果保持输入顺序 --- */
|
|
682
|
+
const results = await Promise.all(hosts.map(async (host) => {
|
|
695
683
|
const res = await lUndici.get('http://' + host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
|
|
696
684
|
'action': 'restart',
|
|
697
|
-
'time':
|
|
685
|
+
'time': lTime.stamp()
|
|
698
686
|
}), globalConfig.rpcSecret), {
|
|
699
687
|
'timeout': 5
|
|
700
688
|
});
|
|
701
689
|
const content = await res.getContent();
|
|
702
690
|
if (!content) {
|
|
703
|
-
|
|
704
|
-
continue;
|
|
691
|
+
return [host, { 'result': false, 'return': 'Timeout' }];
|
|
705
692
|
}
|
|
706
693
|
const str = content.toString();
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
else {
|
|
711
|
-
rtn[host] = { 'result': false, 'return': str };
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
return rtn;
|
|
694
|
+
return [host, { 'result': str === 'Done', 'return': str }];
|
|
695
|
+
}));
|
|
696
|
+
return Object.fromEntries(results);
|
|
715
697
|
}
|
|
716
698
|
/**
|
|
717
699
|
* --- 向主进程(或局域网同代码机子)发送 stop 操作,停止接收新连接并在现有连接全部结束后退出 ---
|
|
@@ -737,31 +719,22 @@ export async function sendStop(hosts) {
|
|
|
737
719
|
if (!hosts?.length) {
|
|
738
720
|
hosts = ['127.0.0.1'];
|
|
739
721
|
}
|
|
740
|
-
|
|
741
|
-
const
|
|
742
|
-
/** --- 返回成功的 host --- */
|
|
743
|
-
const rtn = {};
|
|
744
|
-
for (const host of hosts) {
|
|
722
|
+
/** --- 并行发送,各主机独立等待,结果保持输入顺序 --- */
|
|
723
|
+
const results = await Promise.all(hosts.map(async (host) => {
|
|
745
724
|
const res = await lUndici.get('http://' + host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
|
|
746
725
|
'action': 'stop',
|
|
747
|
-
'time':
|
|
726
|
+
'time': lTime.stamp()
|
|
748
727
|
}), globalConfig.rpcSecret), {
|
|
749
728
|
'timeout': 5
|
|
750
729
|
});
|
|
751
730
|
const content = await res.getContent();
|
|
752
731
|
if (!content) {
|
|
753
|
-
|
|
754
|
-
continue;
|
|
732
|
+
return [host, { 'result': false, 'return': 'Timeout' }];
|
|
755
733
|
}
|
|
756
734
|
const str = content.toString();
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
else {
|
|
761
|
-
rtn[host] = { 'result': false, 'return': str };
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
return rtn;
|
|
735
|
+
return [host, { 'result': str === 'Done', 'return': str }];
|
|
736
|
+
}));
|
|
737
|
+
return Object.fromEntries(results);
|
|
765
738
|
}
|
|
766
739
|
/**
|
|
767
740
|
* --- 向本机或局域网 RPC 发送 PM2 操作 ---
|
|
@@ -778,14 +751,11 @@ export async function sendPm2(name, action = 'restart', hosts) {
|
|
|
778
751
|
if (!hosts?.length) {
|
|
779
752
|
hosts = ['127.0.0.1'];
|
|
780
753
|
}
|
|
781
|
-
|
|
782
|
-
const
|
|
783
|
-
/** --- 返回成功的 host --- */
|
|
784
|
-
const rtn = {};
|
|
785
|
-
for (const host of hosts) {
|
|
754
|
+
/** --- 并行发送,各主机独立等待,结果保持输入顺序 --- */
|
|
755
|
+
const results = await Promise.all(hosts.map(async (host) => {
|
|
786
756
|
const res = await lUndici.get('http://' + host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
|
|
787
757
|
'action': 'pm2',
|
|
788
|
-
'time':
|
|
758
|
+
'time': lTime.stamp(),
|
|
789
759
|
'name': name,
|
|
790
760
|
'pm2Action': action
|
|
791
761
|
}), globalConfig.rpcSecret), {
|
|
@@ -793,19 +763,15 @@ export async function sendPm2(name, action = 'restart', hosts) {
|
|
|
793
763
|
});
|
|
794
764
|
const content = await res.getContent();
|
|
795
765
|
if (!content) {
|
|
796
|
-
|
|
797
|
-
continue;
|
|
766
|
+
return [host, { 'result': false, 'return': 'Timeout' }];
|
|
798
767
|
}
|
|
799
768
|
const str = content.toString();
|
|
800
|
-
if (str
|
|
801
|
-
rtn[host] = { 'result': true, 'return': 'Done' };
|
|
802
|
-
}
|
|
803
|
-
else {
|
|
804
|
-
rtn[host] = { 'result': false, 'return': str };
|
|
769
|
+
if (str !== 'Done') {
|
|
805
770
|
debug('[CORE][sendPm2] rpc server content error:', str);
|
|
806
771
|
}
|
|
807
|
-
|
|
808
|
-
|
|
772
|
+
return [host, { 'result': str === 'Done', 'return': str }];
|
|
773
|
+
}));
|
|
774
|
+
return Object.fromEntries(results);
|
|
809
775
|
}
|
|
810
776
|
/**
|
|
811
777
|
* --- 向本机或局域网 RPC 发送 npm install 操作 ---
|
|
@@ -820,33 +786,26 @@ export async function sendNpm(path, hosts) {
|
|
|
820
786
|
if (!hosts?.length) {
|
|
821
787
|
hosts = ['127.0.0.1'];
|
|
822
788
|
}
|
|
823
|
-
|
|
824
|
-
const
|
|
825
|
-
/** --- 返回成功的 host --- */
|
|
826
|
-
const rtn = {};
|
|
827
|
-
for (const host of hosts) {
|
|
789
|
+
/** --- 并行发送,各主机独立等待,结果保持输入顺序 --- */
|
|
790
|
+
const results = await Promise.all(hosts.map(async (host) => {
|
|
828
791
|
const res = await lUndici.get('http://' + host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
|
|
829
792
|
'action': 'npm',
|
|
830
|
-
'time':
|
|
793
|
+
'time': lTime.stamp(),
|
|
831
794
|
'path': path
|
|
832
795
|
}), globalConfig.rpcSecret), {
|
|
833
796
|
'timeout': 330,
|
|
834
797
|
});
|
|
835
798
|
const content = await res.getContent();
|
|
836
799
|
if (!content) {
|
|
837
|
-
|
|
838
|
-
continue;
|
|
800
|
+
return [host, { 'result': false, 'return': 'Timeout' }];
|
|
839
801
|
}
|
|
840
802
|
const str = content.toString();
|
|
841
|
-
if (str
|
|
842
|
-
rtn[host] = { 'result': true, 'return': 'Done' };
|
|
843
|
-
}
|
|
844
|
-
else {
|
|
845
|
-
rtn[host] = { 'result': false, 'return': str };
|
|
803
|
+
if (str !== 'Done') {
|
|
846
804
|
debug('[CORE][sendNpmInstall] rpc server content error:', str);
|
|
847
805
|
}
|
|
848
|
-
|
|
849
|
-
|
|
806
|
+
return [host, { 'result': str === 'Done', 'return': str }];
|
|
807
|
+
}));
|
|
808
|
+
return Object.fromEntries(results);
|
|
850
809
|
}
|
|
851
810
|
/** --- 跨进程全局变量 --- */
|
|
852
811
|
export const global = {};
|
|
@@ -871,31 +830,24 @@ export async function setGlobal(key, data, hosts) {
|
|
|
871
830
|
if (hosts === 'config') {
|
|
872
831
|
hosts = globalConfig.hosts;
|
|
873
832
|
}
|
|
874
|
-
|
|
875
|
-
const
|
|
876
|
-
/** --- 返回成功的 host --- */
|
|
877
|
-
const rtn = {};
|
|
878
|
-
for (const host of hosts) {
|
|
833
|
+
/** --- 并行发送,各主机独立等待,结果保持输入顺序 --- */
|
|
834
|
+
const results = await Promise.all(hosts.map(async (host) => {
|
|
879
835
|
const res = await lUndici.get('http://' + host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
|
|
880
836
|
'action': 'global',
|
|
881
|
-
'time':
|
|
837
|
+
'time': lTime.stamp(),
|
|
838
|
+
'key': key,
|
|
839
|
+
'data': data
|
|
882
840
|
}), globalConfig.rpcSecret), {
|
|
883
841
|
'timeout': 5
|
|
884
842
|
});
|
|
885
843
|
const content = await res.getContent();
|
|
886
844
|
if (!content) {
|
|
887
|
-
|
|
888
|
-
continue;
|
|
845
|
+
return [host, { 'result': false, 'return': 'Timeout' }];
|
|
889
846
|
}
|
|
890
847
|
const str = content.toString();
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
else {
|
|
895
|
-
rtn[host] = { 'result': false, 'return': str };
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
return rtn;
|
|
848
|
+
return [host, { 'result': str === 'Done', 'return': str }];
|
|
849
|
+
}));
|
|
850
|
+
return Object.fromEntries(results);
|
|
899
851
|
}
|
|
900
852
|
/**
|
|
901
853
|
* --- 移除某个跨线程/跨内网服务器全局变量 ---
|
|
@@ -924,12 +876,11 @@ export async function updateCode(sourcePath, path, hosts, config = true, strict
|
|
|
924
876
|
if (!hosts?.length) {
|
|
925
877
|
hosts = ['127.0.0.1'];
|
|
926
878
|
}
|
|
927
|
-
/** ---
|
|
928
|
-
const
|
|
929
|
-
for (const host of hosts) {
|
|
879
|
+
/** --- 各主机使用独立上传流并行部署,结果保持输入顺序 --- */
|
|
880
|
+
const results = await Promise.all(hosts.map(async (host) => {
|
|
930
881
|
const fd = lUndici.getFormData();
|
|
931
882
|
if (!await fd.putFile('file', sourcePath)) {
|
|
932
|
-
|
|
883
|
+
return;
|
|
933
884
|
}
|
|
934
885
|
fd.putString('path', path);
|
|
935
886
|
fd.putString('config', config);
|
|
@@ -942,19 +893,12 @@ export async function updateCode(sourcePath, path, hosts, config = true, strict
|
|
|
942
893
|
});
|
|
943
894
|
const content = await res.getContent();
|
|
944
895
|
if (!content) {
|
|
945
|
-
|
|
946
|
-
'result': false,
|
|
947
|
-
'return': 'Network error'
|
|
948
|
-
};
|
|
949
|
-
continue;
|
|
896
|
+
return [host, { 'result': false, 'return': 'Network error' }];
|
|
950
897
|
}
|
|
951
898
|
const str = content.toString();
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
};
|
|
956
|
-
}
|
|
957
|
-
return rtn;
|
|
899
|
+
return [host, { 'result': str === 'Done', 'return': str }];
|
|
900
|
+
}));
|
|
901
|
+
return Object.fromEntries(results.filter(result => result !== undefined));
|
|
958
902
|
}
|
|
959
903
|
/**
|
|
960
904
|
* --- 向本机或局域网 RPC 发送项目配置更新操作 ---
|
|
@@ -971,14 +915,11 @@ export async function sendProject(path, key, value, hosts) {
|
|
|
971
915
|
if (!hosts?.length) {
|
|
972
916
|
hosts = ['127.0.0.1'];
|
|
973
917
|
}
|
|
974
|
-
|
|
975
|
-
const
|
|
976
|
-
/** --- 返回成功的 host --- */
|
|
977
|
-
const rtn = {};
|
|
978
|
-
for (const host of hosts) {
|
|
918
|
+
/** --- 并行发送,各主机独立等待,结果保持输入顺序 --- */
|
|
919
|
+
const results = await Promise.all(hosts.map(async (host) => {
|
|
979
920
|
const res = await lUndici.get('http://' + host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
|
|
980
921
|
'action': 'project',
|
|
981
|
-
'time':
|
|
922
|
+
'time': lTime.stamp(),
|
|
982
923
|
'path': path,
|
|
983
924
|
[key]: value
|
|
984
925
|
}), globalConfig.rpcSecret), {
|
|
@@ -986,19 +927,15 @@ export async function sendProject(path, key, value, hosts) {
|
|
|
986
927
|
});
|
|
987
928
|
const content = await res.getContent();
|
|
988
929
|
if (!content) {
|
|
989
|
-
|
|
990
|
-
continue;
|
|
930
|
+
return [host, { 'result': false, 'return': 'Timeout' }];
|
|
991
931
|
}
|
|
992
932
|
const str = content.toString();
|
|
993
|
-
if (str
|
|
994
|
-
rtn[host] = { 'result': true, 'return': 'Done' };
|
|
995
|
-
}
|
|
996
|
-
else {
|
|
997
|
-
rtn[host] = { 'result': false, 'return': str };
|
|
933
|
+
if (str !== 'Done') {
|
|
998
934
|
debug('[CORE][sendProject] rpc server content error:', str);
|
|
999
935
|
}
|
|
1000
|
-
|
|
1001
|
-
|
|
936
|
+
return [host, { 'result': str === 'Done', 'return': str }];
|
|
937
|
+
}));
|
|
938
|
+
return Object.fromEntries(results);
|
|
1002
939
|
}
|
|
1003
940
|
/**
|
|
1004
941
|
* --- 向本机或局域网 RPC 发送 package.json 更新操作 ---
|
|
@@ -1013,33 +950,26 @@ export async function sendPackage(content, hosts) {
|
|
|
1013
950
|
if (!hosts?.length) {
|
|
1014
951
|
hosts = ['127.0.0.1'];
|
|
1015
952
|
}
|
|
1016
|
-
|
|
1017
|
-
const
|
|
1018
|
-
/** --- 返回成功的 host --- */
|
|
1019
|
-
const rtn = {};
|
|
1020
|
-
for (const host of hosts) {
|
|
953
|
+
/** --- 并行发送,各主机独立等待,结果保持输入顺序 --- */
|
|
954
|
+
const results = await Promise.all(hosts.map(async (host) => {
|
|
1021
955
|
const res = await lUndici.get('http://' + host + ':' + globalConfig.rpcPort.toString() + '/' + lCrypto.aesEncrypt(lText.stringifyJson({
|
|
1022
956
|
'action': 'package',
|
|
1023
|
-
'time':
|
|
957
|
+
'time': lTime.stamp(),
|
|
1024
958
|
'content': content
|
|
1025
959
|
}), globalConfig.rpcSecret), {
|
|
1026
960
|
'timeout': 5
|
|
1027
961
|
});
|
|
1028
962
|
const resContent = await res.getContent();
|
|
1029
963
|
if (!resContent) {
|
|
1030
|
-
|
|
1031
|
-
continue;
|
|
964
|
+
return [host, { 'result': false, 'return': 'Timeout' }];
|
|
1032
965
|
}
|
|
1033
966
|
const str = resContent.toString();
|
|
1034
|
-
if (str
|
|
1035
|
-
rtn[host] = { 'result': true, 'return': 'Done' };
|
|
1036
|
-
}
|
|
1037
|
-
else {
|
|
1038
|
-
rtn[host] = { 'result': false, 'return': str };
|
|
967
|
+
if (str !== 'Done') {
|
|
1039
968
|
debug('[CORE][sendPackage] rpc server content error:', str);
|
|
1040
969
|
}
|
|
1041
|
-
|
|
1042
|
-
|
|
970
|
+
return [host, { 'result': str === 'Done', 'return': str }];
|
|
971
|
+
}));
|
|
972
|
+
return Object.fromEntries(results);
|
|
1043
973
|
}
|
|
1044
974
|
/**
|
|
1045
975
|
* --- 写入文件日志 ---
|
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": [
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"types": "./index.d.ts",
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build-doc": "bash ./utils/build-doc.sh",
|
|
17
|
-
"test:formdata": "node abox/test/formdata.mjs"
|
|
17
|
+
"test:formdata": "node abox/test/formdata.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"
|
|
18
20
|
},
|
|
19
21
|
"bin": {
|
|
20
22
|
"kebab": "./bin/kebab.js"
|