@fangzhongya/utils 0.0.9 → 0.0.15

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.
Files changed (124) hide show
  1. package/dist/basic/array/index.cjs +10 -6
  2. package/dist/basic/array/index.d.cts +1 -0
  3. package/dist/basic/array/index.d.ts +1 -0
  4. package/dist/basic/array/index.js +10 -6
  5. package/dist/basic/array/sortObj.cjs +7 -0
  6. package/dist/basic/array/sortObj.d.cts +10 -0
  7. package/dist/basic/array/sortObj.d.ts +10 -0
  8. package/dist/basic/array/sortObj.js +7 -0
  9. package/dist/basic/index.cjs +19 -16
  10. package/dist/basic/index.d.cts +6 -3
  11. package/dist/basic/index.d.ts +6 -3
  12. package/dist/basic/index.js +18 -15
  13. package/dist/basic/object/index.cjs +15 -9
  14. package/dist/basic/object/index.d.cts +1 -0
  15. package/dist/basic/object/index.d.ts +1 -0
  16. package/dist/basic/object/index.js +16 -10
  17. package/dist/basic/object/objValue.cjs +9 -0
  18. package/dist/basic/object/objValue.d.cts +7 -0
  19. package/dist/basic/object/objValue.d.ts +7 -0
  20. package/dist/basic/object/objValue.js +9 -0
  21. package/dist/basic/string/index.cjs +16 -5
  22. package/dist/basic/string/index.d.cts +1 -0
  23. package/dist/basic/string/index.d.ts +1 -0
  24. package/dist/basic/string/index.js +17 -6
  25. package/dist/basic/string/toFunction.cjs +2 -2
  26. package/dist/basic/string/toFunction.d.cts +15 -7
  27. package/dist/basic/string/toFunction.d.ts +15 -7
  28. package/dist/basic/string/toFunction.js +1 -1
  29. package/dist/basic/string/toJson.cjs +3 -3
  30. package/dist/basic/string/toJson.d.cts +2 -5
  31. package/dist/basic/string/toJson.d.ts +2 -5
  32. package/dist/basic/string/toJson.js +2 -2
  33. package/dist/basic/string/toJsons.cjs +15 -0
  34. package/dist/basic/string/toJsons.d.cts +60 -0
  35. package/dist/basic/string/toJsons.d.ts +60 -0
  36. package/dist/basic/string/toJsons.js +15 -0
  37. package/dist/{chunk-76Y73SZE.cjs → chunk-4VLLDFBC.cjs} +17 -7
  38. package/dist/chunk-5HC662VK.js +432 -0
  39. package/dist/{chunk-VQKOHGV5.cjs → chunk-5WOFUMZG.cjs} +8 -4
  40. package/dist/chunk-754Z5VW6.js +29 -0
  41. package/dist/chunk-7O4MJOHM.js +142 -0
  42. package/dist/chunk-E4WBX6J5.cjs +29 -0
  43. package/dist/chunk-ETMYYVQJ.cjs +432 -0
  44. package/dist/{chunk-QJVB3JIZ.js → chunk-HWR2FRME.js} +1 -1
  45. package/dist/{chunk-22VNKNCE.js → chunk-IEQHKLEL.js} +15 -9
  46. package/dist/chunk-JHV27P2Q.cjs +54 -0
  47. package/dist/{chunk-XIMEYSRM.js → chunk-KE6Z4OCB.js} +3 -3
  48. package/dist/{chunk-GV3KYCYT.js → chunk-N46TJUMT.js} +15 -5
  49. package/dist/chunk-O34QAOO7.js +16 -0
  50. package/dist/{chunk-YHLI3SF7.js → chunk-OVHYLUAS.js} +8 -0
  51. package/dist/chunk-PLNZCEDI.js +442 -0
  52. package/dist/{chunk-V5HVA7TW.cjs → chunk-PV2N6PF2.cjs} +8 -0
  53. package/dist/chunk-QXK4IUBI.cjs +142 -0
  54. package/dist/chunk-RYBJGHXK.cjs +153 -0
  55. package/dist/chunk-U3PZBQ6G.js +54 -0
  56. package/dist/{chunk-JMALVLHV.cjs → chunk-UGT4QBTM.cjs} +13 -7
  57. package/dist/chunk-UHKL2RG3.cjs +80 -0
  58. package/dist/{chunk-2KT66KQH.js → chunk-UN6NW2BW.js} +9 -5
  59. package/dist/chunk-UV6KZOFD.cjs +24 -0
  60. package/dist/{chunk-FCCQIHFD.js → chunk-UZ3LZBJ5.js} +1 -1
  61. package/dist/chunk-V2DXOH6B.cjs +442 -0
  62. package/dist/chunk-XQOH3NGZ.js +153 -0
  63. package/dist/chunk-XW3XIK3D.cjs +16 -0
  64. package/dist/chunk-YKNGDK4I.js +80 -0
  65. package/dist/index-6KUSPX5S.d.cts +9 -0
  66. package/dist/index-B7gdHwF9.d.cts +40 -0
  67. package/dist/{index-EY4Ag8_f.d.cts → index-BU0xla6v.d.cts} +4 -1
  68. package/dist/{index-DBBlm0PZ.d.cts → index-BzNlzEhU.d.cts} +7 -1
  69. package/dist/{index-D92-6As_.d.ts → index-C29DFVeC.d.ts} +3 -1
  70. package/dist/index-CPO1AFVg.d.ts +14 -0
  71. package/dist/index-C_7JHW0u.d.ts +9 -0
  72. package/dist/{index-CsP95PJy.d.ts → index-DOq59RNr.d.ts} +4 -1
  73. package/dist/index-DPrdy8Ms.d.ts +40 -0
  74. package/dist/index-cuR7l2XV.d.cts +14 -0
  75. package/dist/{index-BrxHOuw0.d.cts → index-qUiGxoy_.d.cts} +3 -1
  76. package/dist/{index-DjtNMmhM.d.ts → index-rVnsK7Ft.d.ts} +7 -1
  77. package/dist/index.cjs +32 -27
  78. package/dist/index.d.cts +11 -6
  79. package/dist/index.d.ts +11 -6
  80. package/dist/index.js +33 -28
  81. package/dist/judge/index.cjs +57 -5
  82. package/dist/judge/index.d.cts +1 -0
  83. package/dist/judge/index.d.ts +1 -0
  84. package/dist/judge/index.js +57 -5
  85. package/dist/judge/judge.cjs +55 -0
  86. package/dist/judge/judge.d.cts +155 -0
  87. package/dist/judge/judge.d.ts +155 -0
  88. package/dist/judge/judge.js +55 -0
  89. package/dist/judge/matchs.cjs +3 -3
  90. package/dist/judge/matchs.js +2 -2
  91. package/dist/name/index.cjs +3 -3
  92. package/dist/name/index.js +4 -4
  93. package/dist/node/getPort.js +1 -1
  94. package/dist/node/index.js +2 -2
  95. package/dist/tree/index.cjs +11 -2
  96. package/dist/tree/index.d.cts +1 -0
  97. package/dist/tree/index.d.ts +1 -0
  98. package/dist/tree/index.js +10 -1
  99. package/dist/tree/splitGroup.cjs +12 -0
  100. package/dist/tree/splitGroup.d.cts +15 -0
  101. package/dist/tree/splitGroup.d.ts +15 -0
  102. package/dist/tree/splitGroup.js +12 -0
  103. package/dist/urls/index.cjs +4 -4
  104. package/dist/urls/index.js +4 -4
  105. package/package.json +37 -7
  106. package/dist/chunk-6YI3CDEW.js +0 -35
  107. package/dist/chunk-AFKJQ4QP.js +0 -35
  108. package/dist/chunk-JYPJ5QJ5.cjs +0 -35
  109. package/dist/chunk-M3GDD7L3.cjs +0 -24
  110. package/dist/chunk-T7XQBASK.js +0 -28
  111. package/dist/chunk-U5TCBGC3.cjs +0 -28
  112. package/dist/chunk-ZJIRJ4YJ.cjs +0 -35
  113. package/dist/index-BWAB-b69.d.ts +0 -10
  114. package/dist/index-CIOxFVHu.d.ts +0 -9
  115. package/dist/index-CVNtXK0N.d.ts +0 -14
  116. package/dist/index-D-5HNg2W.d.cts +0 -14
  117. package/dist/index-DTk8hXm8.d.cts +0 -10
  118. package/dist/index-DfmnOk56.d.cts +0 -9
  119. package/dist/{chunk-OXTC52IL.cjs → chunk-222T3EXB.cjs} +3 -3
  120. package/dist/{chunk-IVDRKJ33.js → chunk-BFN33JM5.js} +3 -3
  121. package/dist/{chunk-ZXWKQRGH.cjs → chunk-BG2YS767.cjs} +2 -2
  122. package/dist/{chunk-WVG4AW4U.js → chunk-JM55S2OL.js} +3 -3
  123. package/dist/{chunk-NGQKVTCR.cjs → chunk-T22I7TJQ.cjs} +3 -3
  124. package/dist/{chunk-FRGDQOX4.js → chunk-T2QKEABG.js} +3 -3
@@ -0,0 +1,29 @@
1
+ // packages/basic/object/objValue.ts
2
+ function getObjValue(key, locale) {
3
+ if (!key) return locale;
4
+ const path = key.split(".");
5
+ let result = locale;
6
+ for (const prop of path) {
7
+ if (result == null || typeof result !== "object") return void 0;
8
+ result = result[prop];
9
+ }
10
+ return result;
11
+ }
12
+ function setObjValue(locale, key, value) {
13
+ if (!key) return Object.assign(locale, value);
14
+ const path = key.split(".");
15
+ const lastKey = path.pop();
16
+ let current = locale;
17
+ for (const prop of path) {
18
+ if (!current[prop] || typeof current[prop] !== "object") {
19
+ current[prop] = {};
20
+ }
21
+ current = current[prop];
22
+ }
23
+ current[lastKey] = value;
24
+ }
25
+
26
+ export {
27
+ getObjValue,
28
+ setObjValue
29
+ };
@@ -0,0 +1,142 @@
1
+ // packages/basic/string/toFunction.ts
2
+ function extractParams(paramStr) {
3
+ const result = [];
4
+ let depth = 0;
5
+ let current = "";
6
+ let inString = false;
7
+ let quoteType = "";
8
+ let lastChar = "";
9
+ for (let i = 0; i < paramStr.length; i++) {
10
+ const char = paramStr[i];
11
+ if (lastChar === "\\") {
12
+ current += char;
13
+ lastChar = char;
14
+ continue;
15
+ }
16
+ if (!inString && (char === '"' || char === "'" || char === "`")) {
17
+ inString = true;
18
+ quoteType = char;
19
+ } else if (inString && char === quoteType) {
20
+ inString = false;
21
+ }
22
+ if (quoteType === "`" && char === "$" && i < paramStr.length - 1 && paramStr[i + 1] === "{") {
23
+ depth++;
24
+ } else if (quoteType === "`" && depth > 0 && char === "}") {
25
+ depth--;
26
+ }
27
+ if (char === "," && depth === 0 && !inString) {
28
+ result.push(current.trim());
29
+ current = "";
30
+ } else {
31
+ if (char === "(" || char === "{" || char === "[") depth++;
32
+ else if (char === ")" || char === "}" || char === "]") depth--;
33
+ current += char;
34
+ }
35
+ lastChar = char;
36
+ }
37
+ if (current.trim()) result.push(current.trim());
38
+ return result;
39
+ }
40
+ function toFunction(str, key) {
41
+ try {
42
+ const obj = getFunctionFormat(str);
43
+ if (!obj?.body) return void 0;
44
+ const params = obj.param ? extractParams(obj.param) : [];
45
+ if (params.length > 1e3) {
46
+ throw new Error("Too many parameters (max: 1000)");
47
+ }
48
+ if (obj.isAsync) {
49
+ try {
50
+ const fullFunction = `async function${obj.isGenerator ? "*" : ""} ${obj.name ?? key ?? ""} (${obj.param}) { ${obj.body} }`;
51
+ return new Function(`return ${fullFunction}`)();
52
+ } catch (error) {
53
+ const fullFunction = `async function${obj.isGenerator ? "*" : ""} (${obj.param}) { ${obj.body} }`;
54
+ return new Function(`return ${fullFunction}`)();
55
+ }
56
+ } else {
57
+ try {
58
+ const fullFunction = `function${obj.isGenerator ? "*" : ""} ${obj.name ?? key ?? ""}(${obj.param}) { ${obj.body} }`;
59
+ return new Function(`return (${fullFunction})`)();
60
+ } catch (error) {
61
+ return new Function(...params, obj.body);
62
+ }
63
+ }
64
+ } catch (error) {
65
+ console.error("Function creation failed:", {
66
+ input: str.slice(0, 100),
67
+ error
68
+ });
69
+ return void 0;
70
+ }
71
+ }
72
+ var FUNCTION_REGEX = /^\s*(?:(async)\s+)?(?:function\s*(\*?)\s*(\w*)\s*\(([\s\S]*?)\)|(\*?\s*)\b(\w+)\s*\(([\s\S]*?)\)|\(([\s\S]*?)\)|([^=>,\(\)]+?))\s*(?:=>)?\s*(?:\{([\s\S]*?)\}|([\s\S]*))$/;
73
+ function getFunctionFormat(v) {
74
+ if (!v) return;
75
+ const str = typeof v === "function" ? v.toString() : v;
76
+ const trimmed = str.trim();
77
+ const match = trimmed.match(FUNCTION_REGEX);
78
+ if (!match) {
79
+ console.warn("Unsupported function format:", trimmed.slice(0, 100));
80
+ return;
81
+ }
82
+ const [
83
+ _,
84
+ // 完整匹配
85
+ asyncFlag,
86
+ // 异步标志
87
+ funcGenerator,
88
+ // 函数生成器标志
89
+ funcName,
90
+ // 函数名称
91
+ funcParams,
92
+ // 函数参数
93
+ methodGenerator,
94
+ // 方法生成器标志
95
+ methodName,
96
+ // 方法名称
97
+ methodParams,
98
+ // 方法参数
99
+ arrowParenParams,
100
+ // 箭头函数括号参数
101
+ arrowSingleParam,
102
+ // 箭头函数单参数
103
+ blockBody,
104
+ // 块级函数体
105
+ exprBody
106
+ // 表达式函数体
107
+ ] = match;
108
+ let isAsync = !!asyncFlag;
109
+ let isGenerator = false;
110
+ let name = "";
111
+ let param = "";
112
+ let body = "";
113
+ if (funcParams !== void 0) {
114
+ isGenerator = funcGenerator === "*";
115
+ name = funcName || "";
116
+ param = funcParams;
117
+ body = blockBody || exprBody || "";
118
+ } else if (methodParams !== void 0) {
119
+ isGenerator = methodGenerator?.includes("*") || false;
120
+ name = methodName || "";
121
+ param = methodParams;
122
+ body = blockBody || exprBody || "";
123
+ } else if (arrowParenParams !== void 0 || arrowSingleParam !== void 0) {
124
+ param = arrowParenParams || arrowSingleParam || "";
125
+ body = blockBody || exprBody || "";
126
+ if (!blockBody && !/^\s*return\b/.test(body)) {
127
+ body = `return ${body}`;
128
+ }
129
+ }
130
+ return {
131
+ isAsync,
132
+ isGenerator,
133
+ ...name && { name },
134
+ param: param.trim(),
135
+ body: body.trim()
136
+ };
137
+ }
138
+
139
+ export {
140
+ toFunction,
141
+ getFunctionFormat
142
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// packages/basic/object/objValue.ts
2
+ function getObjValue(key, locale) {
3
+ if (!key) return locale;
4
+ const path = key.split(".");
5
+ let result = locale;
6
+ for (const prop of path) {
7
+ if (result == null || typeof result !== "object") return void 0;
8
+ result = result[prop];
9
+ }
10
+ return result;
11
+ }
12
+ function setObjValue(locale, key, value) {
13
+ if (!key) return Object.assign(locale, value);
14
+ const path = key.split(".");
15
+ const lastKey = path.pop();
16
+ let current = locale;
17
+ for (const prop of path) {
18
+ if (!current[prop] || typeof current[prop] !== "object") {
19
+ current[prop] = {};
20
+ }
21
+ current = current[prop];
22
+ }
23
+ current[lastKey] = value;
24
+ }
25
+
26
+
27
+
28
+
29
+ exports.getObjValue = getObjValue; exports.setObjValue = setObjValue;
@@ -0,0 +1,432 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunkQXK4IUBIcjs = require('./chunk-QXK4IUBI.cjs');
4
+
5
+
6
+ var _chunkE4WBX6J5cjs = require('./chunk-E4WBX6J5.cjs');
7
+
8
+ // packages/basic/string/toJsons.ts
9
+ var TYPE_MARKERS = {
10
+ FUNCTION_REF: "_FR_",
11
+ CODE_BLOCK: "_CB_",
12
+ /**内置对象*/
13
+ SYMBOL: "_Sy_",
14
+ FUNCTION: "_F_",
15
+ UNDEFINED: "_UN_",
16
+ DATE: "_D_",
17
+ REGEXP: "_R_",
18
+ NAN: "_N_",
19
+ BIGINT: "_BI_",
20
+ MAP: "_M_",
21
+ SET: "_S_",
22
+ ARRAY_BUFFER: "_AB_",
23
+ TYPED_ARRAY: "_TA_",
24
+ DATA_VIEW: "_DV_",
25
+ ERROR: "_E_",
26
+ URL: "_U_",
27
+ INFINITY: "_I_",
28
+ NEGATIVE_INFINITY: "_NI_",
29
+ INT8_ARRAY: "_I8_",
30
+ UINT8_ARRAY: "_U8_",
31
+ UINT8_CLAMPED_ARRAY: "_U8C_",
32
+ INT16_ARRAY: "_I1_",
33
+ UINT16_ARRAY: "_U1_",
34
+ INT32_ARRAY: "_I3_",
35
+ UINT32_ARRAY: "_U3_",
36
+ FLOAT32_ARRAY: "_F3_",
37
+ FLOAT64_ARRAY: "_F6_",
38
+ BIGINT64_ARRAY: "_BI6_",
39
+ BIGUINT64_ARRAY: "_BU6_"
40
+ };
41
+ var arrayBufferUtils = {
42
+ // 将ArrayBuffer编码为Base64字符串
43
+ encode: (buffer) => {
44
+ if (typeof Buffer !== "undefined") {
45
+ const bytes = new Uint8Array(buffer);
46
+ let binary = "";
47
+ bytes.forEach((byte) => binary += String.fromCharCode(byte));
48
+ return btoa(binary);
49
+ }
50
+ if (typeof btoa === "function") {
51
+ const bytes = new Uint8Array(buffer);
52
+ let binary = "";
53
+ for (let i = 0; i < bytes.byteLength; i++) {
54
+ binary += String.fromCharCode(bytes[i]);
55
+ }
56
+ return btoa(binary);
57
+ }
58
+ throw new Error(
59
+ "ArrayBuffer encoding not supported in this environment"
60
+ );
61
+ },
62
+ // 将Base64字符串解码为ArrayBuffer
63
+ decode: (base64Str) => {
64
+ if (typeof Buffer !== "undefined") {
65
+ const binaryString = atob(base64Str);
66
+ const bytes = new Uint8Array(binaryString.length);
67
+ for (let i = 0; i < binaryString.length; i++) {
68
+ bytes[i] = binaryString.charCodeAt(i);
69
+ }
70
+ return bytes.buffer;
71
+ }
72
+ if (typeof atob === "function") {
73
+ const binaryString = atob(base64Str);
74
+ const bytes = new Uint8Array(binaryString.length);
75
+ for (let i = 0; i < binaryString.length; i++) {
76
+ bytes[i] = binaryString.charCodeAt(i);
77
+ }
78
+ return bytes.buffer;
79
+ }
80
+ throw new Error(
81
+ "ArrayBuffer decoding not supported in this environment"
82
+ );
83
+ },
84
+ // 获取ArrayBuffer的字节数组表示
85
+ toByteArray: (buffer) => {
86
+ return Array.from(new Uint8Array(buffer));
87
+ },
88
+ // 从字节数组创建ArrayBuffer
89
+ fromByteArray: (array) => {
90
+ const buffer = new ArrayBuffer(array.length);
91
+ const view = new Uint8Array(buffer);
92
+ array.forEach((value, index) => view[index] = value);
93
+ return buffer;
94
+ }
95
+ };
96
+ function toJSONSStringify(obj, space) {
97
+ const seen = /* @__PURE__ */ new WeakSet();
98
+ return JSON.stringify(
99
+ obj,
100
+ function(key, value) {
101
+ if (value === null) {
102
+ return null;
103
+ }
104
+ if (typeof value === "object") {
105
+ if (seen.has(value)) return "[Circular]";
106
+ seen.add(value);
107
+ }
108
+ if (this[key] instanceof Date) {
109
+ return {
110
+ [TYPE_MARKERS.DATE]: this[key].getTime()
111
+ };
112
+ }
113
+ if (this[key] instanceof URL) {
114
+ return {
115
+ [TYPE_MARKERS.URL]: this[key].href
116
+ };
117
+ }
118
+ if (value === Infinity) {
119
+ return { [TYPE_MARKERS.INFINITY]: 1 };
120
+ }
121
+ if (value === -Infinity) {
122
+ return { [TYPE_MARKERS.NEGATIVE_INFINITY]: 1 };
123
+ }
124
+ if (value === void 0) {
125
+ return { [TYPE_MARKERS.UNDEFINED]: 1 };
126
+ }
127
+ if (Object.is(value, NaN)) {
128
+ return { [TYPE_MARKERS.NAN]: 1 };
129
+ }
130
+ switch (typeof value) {
131
+ case "bigint":
132
+ return { [TYPE_MARKERS.BIGINT]: value.toString() };
133
+ case "symbol":
134
+ return {
135
+ [TYPE_MARKERS.SYMBOL]: {
136
+ k: _nullishCoalesce(Symbol.keyFor(value), () => ( 0)),
137
+ d: value.description || ""
138
+ }
139
+ };
140
+ case "function":
141
+ return {
142
+ [TYPE_MARKERS.FUNCTION]: value.toString()
143
+ };
144
+ case "object":
145
+ if (value instanceof RegExp) {
146
+ return {
147
+ [TYPE_MARKERS.REGEXP]: {
148
+ s: value.source,
149
+ f: value.flags
150
+ }
151
+ };
152
+ }
153
+ if (value instanceof Map) {
154
+ return {
155
+ [TYPE_MARKERS.MAP]: Array.from(value.entries())
156
+ };
157
+ }
158
+ if (value instanceof Set) {
159
+ return {
160
+ [TYPE_MARKERS.SET]: Array.from(value.values())
161
+ };
162
+ }
163
+ if (value instanceof ArrayBuffer) {
164
+ return {
165
+ [TYPE_MARKERS.ARRAY_BUFFER]: arrayBufferUtils.encode(value)
166
+ };
167
+ }
168
+ if (value instanceof Int8Array) {
169
+ return {
170
+ [TYPE_MARKERS.INT8_ARRAY]: arrayBufferUtils.toByteArray(value.buffer)
171
+ };
172
+ }
173
+ if (value instanceof Uint8Array) {
174
+ return {
175
+ [TYPE_MARKERS.UINT8_ARRAY]: arrayBufferUtils.toByteArray(value.buffer)
176
+ };
177
+ }
178
+ if (value instanceof Uint8ClampedArray) {
179
+ return {
180
+ [TYPE_MARKERS.UINT8_CLAMPED_ARRAY]: arrayBufferUtils.toByteArray(value.buffer)
181
+ };
182
+ }
183
+ if (value instanceof Int16Array) {
184
+ return {
185
+ [TYPE_MARKERS.INT16_ARRAY]: arrayBufferUtils.toByteArray(value.buffer)
186
+ };
187
+ }
188
+ if (value instanceof Uint16Array) {
189
+ return {
190
+ [TYPE_MARKERS.UINT16_ARRAY]: arrayBufferUtils.toByteArray(value.buffer)
191
+ };
192
+ }
193
+ if (value instanceof Int32Array) {
194
+ return {
195
+ [TYPE_MARKERS.INT32_ARRAY]: arrayBufferUtils.toByteArray(value.buffer)
196
+ };
197
+ }
198
+ if (value instanceof Uint32Array) {
199
+ return {
200
+ [TYPE_MARKERS.UINT32_ARRAY]: arrayBufferUtils.toByteArray(value.buffer)
201
+ };
202
+ }
203
+ if (value instanceof Float32Array) {
204
+ return {
205
+ [TYPE_MARKERS.FLOAT32_ARRAY]: arrayBufferUtils.toByteArray(value.buffer)
206
+ };
207
+ }
208
+ if (value instanceof Float64Array) {
209
+ return {
210
+ [TYPE_MARKERS.FLOAT64_ARRAY]: arrayBufferUtils.toByteArray(value.buffer)
211
+ };
212
+ }
213
+ if (value instanceof BigInt64Array) {
214
+ return {
215
+ [TYPE_MARKERS.BIGINT64_ARRAY]: arrayBufferUtils.toByteArray(value.buffer)
216
+ };
217
+ }
218
+ if (value instanceof BigUint64Array) {
219
+ return {
220
+ [TYPE_MARKERS.BIGUINT64_ARRAY]: arrayBufferUtils.toByteArray(value.buffer)
221
+ };
222
+ }
223
+ if (value instanceof DataView) {
224
+ return {
225
+ [TYPE_MARKERS.DATA_VIEW]: {
226
+ b: arrayBufferUtils.encode(
227
+ value.buffer
228
+ ),
229
+ o: value.byteOffset,
230
+ l: value.byteLength
231
+ }
232
+ };
233
+ }
234
+ if (value instanceof Error) {
235
+ return {
236
+ [TYPE_MARKERS.ERROR]: {
237
+ n: value.name,
238
+ m: value.message,
239
+ s: value.stack
240
+ }
241
+ };
242
+ }
243
+ }
244
+ return value;
245
+ },
246
+ space
247
+ );
248
+ }
249
+ function toJSONSParse(str, context) {
250
+ try {
251
+ const parsed = JSON.parse(str, (key, value) => {
252
+ if (value && typeof value === "object") {
253
+ const markers = Object.keys(value);
254
+ if (markers.length === 1) {
255
+ const marker = markers[0];
256
+ const markerValue = value[marker];
257
+ switch (marker) {
258
+ case TYPE_MARKERS.BIGINT:
259
+ return BigInt(markerValue);
260
+ case TYPE_MARKERS.SYMBOL:
261
+ return markerValue.k ? Symbol.for(markerValue.k) : Symbol(markerValue.d);
262
+ case TYPE_MARKERS.FUNCTION:
263
+ return _chunkQXK4IUBIcjs.toFunction.call(void 0, markerValue, key) || function() {
264
+ };
265
+ case TYPE_MARKERS.NAN:
266
+ return NaN;
267
+ case TYPE_MARKERS.INFINITY:
268
+ return Infinity;
269
+ case TYPE_MARKERS.NEGATIVE_INFINITY:
270
+ return -Infinity;
271
+ case TYPE_MARKERS.FUNCTION_REF:
272
+ return context ? _chunkE4WBX6J5cjs.getObjValue.call(void 0, markerValue, context) : void 0;
273
+ case TYPE_MARKERS.CODE_BLOCK:
274
+ return getCodeBlock(markerValue, key);
275
+ }
276
+ }
277
+ }
278
+ return value;
279
+ });
280
+ return restoreSpecialValues(parsed);
281
+ } catch (error) {
282
+ console.error("JSON parse error:", {
283
+ str: str.slice(0, 200) + "...",
284
+ error
285
+ });
286
+ return {};
287
+ }
288
+ }
289
+ function restoreSpecialValues(obj, depth = 0) {
290
+ if (depth > 100) throw new Error("Recursion limit exceeded");
291
+ if (obj === null || typeof obj !== "object") {
292
+ return obj;
293
+ }
294
+ if (Array.isArray(obj)) {
295
+ return obj.map((item) => {
296
+ const converted = convertSpecialValue(item);
297
+ if (converted !== item) {
298
+ return converted;
299
+ }
300
+ return restoreSpecialValues(item, depth + 1);
301
+ });
302
+ }
303
+ const result = {};
304
+ for (const key in obj) {
305
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
306
+ let value = obj[key];
307
+ const converted = convertSpecialValue(value);
308
+ if (converted !== value) {
309
+ value = converted;
310
+ } else {
311
+ value = restoreSpecialValues(value, depth + 1);
312
+ }
313
+ result[key] = value;
314
+ }
315
+ }
316
+ return result;
317
+ }
318
+ function convertSpecialValue(value) {
319
+ if (value && typeof value === "object") {
320
+ const keys = Object.keys(value);
321
+ if (keys.length === 1) {
322
+ const [marker] = keys;
323
+ const markerValue = value[marker];
324
+ switch (marker) {
325
+ case TYPE_MARKERS.UNDEFINED:
326
+ return void 0;
327
+ case TYPE_MARKERS.DATE:
328
+ return new Date(markerValue);
329
+ // 从时间戳恢复Date
330
+ case TYPE_MARKERS.REGEXP: {
331
+ return new RegExp(markerValue.s, markerValue.f);
332
+ }
333
+ case TYPE_MARKERS.MAP:
334
+ return new Map(markerValue);
335
+ case TYPE_MARKERS.SET:
336
+ return new Set(markerValue);
337
+ case TYPE_MARKERS.ARRAY_BUFFER:
338
+ return arrayBufferUtils.decode(markerValue);
339
+ case TYPE_MARKERS.ERROR: {
340
+ const { n, m, s } = markerValue;
341
+ const error = new Error(m);
342
+ error.name = n;
343
+ error.stack = s;
344
+ return error;
345
+ }
346
+ case TYPE_MARKERS.URL:
347
+ return new URL(markerValue);
348
+ // 处理所有TypedArray类型
349
+ case TYPE_MARKERS.INT8_ARRAY:
350
+ return new Int8Array(
351
+ arrayBufferUtils.fromByteArray(markerValue)
352
+ );
353
+ case TYPE_MARKERS.UINT8_ARRAY:
354
+ return new Uint8Array(
355
+ arrayBufferUtils.fromByteArray(markerValue)
356
+ );
357
+ case TYPE_MARKERS.UINT8_CLAMPED_ARRAY:
358
+ return new Uint8ClampedArray(
359
+ arrayBufferUtils.fromByteArray(markerValue)
360
+ );
361
+ case TYPE_MARKERS.INT16_ARRAY:
362
+ return new Int16Array(
363
+ arrayBufferUtils.fromByteArray(markerValue)
364
+ );
365
+ case TYPE_MARKERS.UINT16_ARRAY:
366
+ return new Uint16Array(
367
+ arrayBufferUtils.fromByteArray(markerValue)
368
+ );
369
+ case TYPE_MARKERS.INT32_ARRAY:
370
+ return new Int32Array(
371
+ arrayBufferUtils.fromByteArray(markerValue)
372
+ );
373
+ case TYPE_MARKERS.UINT32_ARRAY:
374
+ return new Uint32Array(
375
+ arrayBufferUtils.fromByteArray(markerValue)
376
+ );
377
+ case TYPE_MARKERS.FLOAT32_ARRAY:
378
+ return new Float32Array(
379
+ arrayBufferUtils.fromByteArray(markerValue)
380
+ );
381
+ case TYPE_MARKERS.FLOAT64_ARRAY:
382
+ return new Float64Array(
383
+ arrayBufferUtils.fromByteArray(markerValue)
384
+ );
385
+ case TYPE_MARKERS.BIGINT64_ARRAY:
386
+ return new BigInt64Array(
387
+ arrayBufferUtils.fromByteArray(markerValue)
388
+ );
389
+ case TYPE_MARKERS.BIGUINT64_ARRAY:
390
+ return new BigUint64Array(
391
+ arrayBufferUtils.fromByteArray(markerValue)
392
+ );
393
+ case TYPE_MARKERS.DATA_VIEW: {
394
+ const buffer = arrayBufferUtils.decode(markerValue.b);
395
+ return new DataView(buffer, markerValue.o, markerValue.l);
396
+ }
397
+ }
398
+ }
399
+ }
400
+ return value;
401
+ }
402
+ function getCodeBlock(value, key) {
403
+ try {
404
+ try {
405
+ const fullFunction = `function ${_nullishCoalesce(_nullishCoalesce(value.name, () => ( key)), () => ( ""))}(${value.params.join(",")}) { ${value.body} }`;
406
+ return new Function(`"use strict";
407
+ return (${fullFunction})`)();
408
+ } catch (error) {
409
+ return new Function(
410
+ ...value.params,
411
+ `"use strict";
412
+ ${value.body}`
413
+ );
414
+ }
415
+ } catch (error) {
416
+ console.error("Code block execution failed", error);
417
+ return value;
418
+ }
419
+ }
420
+ function serializeFunctionRef(key) {
421
+ return { [TYPE_MARKERS.FUNCTION_REF]: key };
422
+ }
423
+ function serializeCodeBlock(value) {
424
+ return { [TYPE_MARKERS.CODE_BLOCK]: value };
425
+ }
426
+
427
+
428
+
429
+
430
+
431
+
432
+ exports.toJSONSStringify = toJSONSStringify; exports.toJSONSParse = toJSONSParse; exports.serializeFunctionRef = serializeFunctionRef; exports.serializeCodeBlock = serializeCodeBlock;
@@ -1,5 +1,5 @@
1
1
  // packages/node/getPort.ts
2
- import { createServer } from "node:net";
2
+ import { createServer } from "net";
3
3
  function getPort(host, port = 5173, isLocal = true) {
4
4
  return new Promise((resolve, reject) => {
5
5
  isPortOccupied(port, host, isLocal).then((v) => {
@@ -1,21 +1,19 @@
1
- import {
2
- unmergeObject
3
- } from "./chunk-A6J46LQK.js";
4
- import {
5
- getSort
6
- } from "./chunk-ZEAT23CI.js";
7
- import {
8
- hasOwn
9
- } from "./chunk-3IR2ABRO.js";
10
1
  import {
11
2
  mergeObject
12
3
  } from "./chunk-RD4EP3M5.js";
4
+ import {
5
+ getObjValue,
6
+ setObjValue
7
+ } from "./chunk-754Z5VW6.js";
13
8
  import {
14
9
  reverseObj
15
10
  } from "./chunk-B3IGSYZT.js";
16
11
  import {
17
12
  setSort
18
13
  } from "./chunk-3LWFUVER.js";
14
+ import {
15
+ unmergeObject
16
+ } from "./chunk-A6J46LQK.js";
19
17
  import {
20
18
  attrValueSort
21
19
  } from "./chunk-T4BAVDTH.js";
@@ -25,6 +23,12 @@ import {
25
23
  import {
26
24
  filterObject
27
25
  } from "./chunk-S42NGJ5W.js";
26
+ import {
27
+ getSort
28
+ } from "./chunk-ZEAT23CI.js";
29
+ import {
30
+ hasOwn
31
+ } from "./chunk-3IR2ABRO.js";
28
32
  import {
29
33
  isObjectArray
30
34
  } from "./chunk-GYE23WAN.js";
@@ -41,12 +45,14 @@ __export(object_exports, {
41
45
  attrValueSort: () => attrValueSort,
42
46
  deepCopy: () => deepCopy,
43
47
  filterObject: () => filterObject,
48
+ getObjValue: () => getObjValue,
44
49
  getSort: () => getSort,
45
50
  hasOwn: () => hasOwn,
46
51
  isObject: () => isObject,
47
52
  isObjectArray: () => isObjectArray,
48
53
  mergeObject: () => mergeObject,
49
54
  reverseObj: () => reverseObj,
55
+ setObjValue: () => setObjValue,
50
56
  setSort: () => setSort,
51
57
  unmergeObject: () => unmergeObject
52
58
  });