@fangzhongya/utils 0.0.60 → 0.0.62

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 (61) hide show
  1. package/dist/basic/index.cjs +22 -21
  2. package/dist/basic/index.d.cts +2 -1
  3. package/dist/basic/index.d.ts +2 -1
  4. package/dist/basic/index.js +21 -20
  5. package/dist/basic/object/index.cjs +9 -9
  6. package/dist/basic/object/index.js +10 -10
  7. package/dist/basic/string/index.cjs +22 -14
  8. package/dist/basic/string/index.d.cts +2 -1
  9. package/dist/basic/string/index.d.ts +2 -1
  10. package/dist/basic/string/index.js +26 -18
  11. package/dist/basic/string/toFunction.cjs +4 -2
  12. package/dist/basic/string/toFunction.d.cts +12 -3
  13. package/dist/basic/string/toFunction.d.ts +12 -3
  14. package/dist/basic/string/toFunction.js +3 -1
  15. package/dist/basic/string/toFunctionParam.cjs +10 -0
  16. package/dist/basic/string/toFunctionParam.d.cts +18 -0
  17. package/dist/basic/string/toFunctionParam.d.ts +18 -0
  18. package/dist/basic/string/toFunctionParam.js +10 -0
  19. package/dist/basic/string/toJson.cjs +3 -3
  20. package/dist/basic/string/toJson.js +2 -2
  21. package/dist/basic/string/toJsons.cjs +3 -3
  22. package/dist/basic/string/toJsons.js +2 -2
  23. package/dist/basic/string/toStringParse.cjs +3 -3
  24. package/dist/basic/string/toStringParse.js +2 -2
  25. package/dist/{chunk-MGK5PCGH.js → chunk-ADPTUJSF.js} +1 -1
  26. package/dist/{chunk-BT2SXUJY.js → chunk-BUMAKEB5.js} +24 -16
  27. package/dist/{chunk-3FQKILLZ.cjs → chunk-ENKAUJ2M.cjs} +3 -3
  28. package/dist/{chunk-LMKPAAY6.cjs → chunk-G7IWN7T3.cjs} +28 -20
  29. package/dist/{chunk-XG44HG5N.cjs → chunk-HLKHFBMF.cjs} +2 -2
  30. package/dist/{chunk-QXK4IUBI.cjs → chunk-JJ37YIPJ.cjs} +42 -35
  31. package/dist/{chunk-JHV27P2Q.cjs → chunk-K2XKKEE7.cjs} +2 -2
  32. package/dist/{chunk-Y6UWNHC6.js → chunk-L6NTBIT6.js} +4 -4
  33. package/dist/{chunk-7O4MJOHM.js → chunk-Q6BNW3MO.js} +42 -35
  34. package/dist/chunk-SE2X5XKO.js +129 -0
  35. package/dist/{chunk-U3PZBQ6G.js → chunk-TIZFQBWC.js} +1 -1
  36. package/dist/{chunk-HXG4I4YA.cjs → chunk-V6CQKJQI.cjs} +4 -4
  37. package/dist/{chunk-SXTTMHYU.js → chunk-ZVSPZZHD.js} +3 -3
  38. package/dist/chunk-ZZKR5C3Y.cjs +129 -0
  39. package/dist/{index-DLnJJBhb.d.cts → index-BMhmeVcw.d.cts} +1 -1
  40. package/dist/{index-CxW0zCsG.d.cts → index-BmGaGt2M.d.cts} +7 -2
  41. package/dist/{index-CnVIRWwZ.d.ts → index-CGsG3tMc.d.ts} +1 -1
  42. package/dist/{index-zLctRwm9.d.ts → index-CRh3wZkY.d.ts} +7 -2
  43. package/dist/index.cjs +36 -35
  44. package/dist/index.d.cts +3 -2
  45. package/dist/index.d.ts +3 -2
  46. package/dist/index.js +35 -34
  47. package/dist/tree/index.cjs +3 -3
  48. package/dist/tree/index.js +6 -6
  49. package/dist/urls/index.cjs +4 -4
  50. package/dist/urls/index.js +4 -4
  51. package/dist/window/index.cjs +4 -4
  52. package/dist/window/index.js +7 -7
  53. package/package.json +6 -1
  54. package/dist/{chunk-HQ6ASUBP.js → chunk-3DUFQKFF.js} +3 -3
  55. package/dist/{chunk-E74ZD4NG.cjs → chunk-72GMBSE6.cjs} +3 -3
  56. package/dist/{chunk-XARZ3OMM.cjs → chunk-7GCUYESU.cjs} +3 -3
  57. package/dist/{chunk-PFTTRHAB.js → chunk-7M7ORCKS.js} +9 -9
  58. package/dist/{chunk-PV2N6PF2.cjs → chunk-APRM3ELY.cjs} +2 -2
  59. package/dist/{chunk-FJ5PJYIY.cjs → chunk-KZCLX66D.cjs} +8 -8
  60. package/dist/{chunk-5WQXANBO.js → chunk-MZLWYQQH.js} +6 -6
  61. package/dist/{chunk-OVHYLUAS.js → chunk-QUIZWAFR.js} +5 -5
@@ -1,8 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkXG44HG5Ncjs = require('../../chunk-XG44HG5N.cjs');
4
- require('../../chunk-QXK4IUBI.cjs');
3
+ var _chunkHLKHFBMFcjs = require('../../chunk-HLKHFBMF.cjs');
4
+ require('../../chunk-JJ37YIPJ.cjs');
5
5
  require('../../chunk-75ZPJI57.cjs');
6
6
 
7
7
 
8
- exports.toStringParse = _chunkXG44HG5Ncjs.toStringParse;
8
+ exports.toStringParse = _chunkHLKHFBMFcjs.toStringParse;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  toStringParse
3
- } from "../../chunk-MGK5PCGH.js";
4
- import "../../chunk-7O4MJOHM.js";
3
+ } from "../../chunk-ADPTUJSF.js";
4
+ import "../../chunk-Q6BNW3MO.js";
5
5
  import "../../chunk-MLKGABMK.js";
6
6
  export {
7
7
  toStringParse
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  toFunction
3
- } from "./chunk-7O4MJOHM.js";
3
+ } from "./chunk-Q6BNW3MO.js";
4
4
 
5
5
  // packages/basic/string/toStringParse.ts
6
6
  var arrayBufferUtils = {
@@ -1,24 +1,20 @@
1
+ import {
2
+ toFunctionParam,
3
+ toFunctionParamOptions
4
+ } from "./chunk-SE2X5XKO.js";
1
5
  import {
2
6
  toJSONParse,
3
7
  toJSONStringify
4
- } from "./chunk-U3PZBQ6G.js";
8
+ } from "./chunk-TIZFQBWC.js";
5
9
  import {
6
10
  serializeCodeBlock,
7
11
  serializeFunctionRef,
8
12
  toJSONSParse,
9
13
  toJSONSStringify
10
- } from "./chunk-SXTTMHYU.js";
14
+ } from "./chunk-ZVSPZZHD.js";
11
15
  import {
12
16
  toStringParse
13
- } from "./chunk-MGK5PCGH.js";
14
- import {
15
- getFunctionFormat,
16
- toFunction
17
- } from "./chunk-7O4MJOHM.js";
18
- import {
19
- getContent,
20
- getContents
21
- } from "./chunk-YKSVLAAK.js";
17
+ } from "./chunk-ADPTUJSF.js";
22
18
  import {
23
19
  getImports,
24
20
  getImportss
@@ -29,15 +25,18 @@ import {
29
25
  import {
30
26
  splitUpper
31
27
  } from "./chunk-VKE5JARB.js";
28
+ import {
29
+ extractParams,
30
+ getFunctionFormat,
31
+ toFunction
32
+ } from "./chunk-Q6BNW3MO.js";
32
33
  import {
33
34
  deComment
34
35
  } from "./chunk-FS4JPT23.js";
35
36
  import {
36
- firstLower
37
- } from "./chunk-4OBNLDTJ.js";
38
- import {
39
- firstUpper
40
- } from "./chunk-EWJJKQIO.js";
37
+ getContent,
38
+ getContents
39
+ } from "./chunk-YKSVLAAK.js";
41
40
  import {
42
41
  getStrNunPosit
43
42
  } from "./chunk-USIMBBLW.js";
@@ -53,6 +52,12 @@ import {
53
52
  import {
54
53
  getStartSames
55
54
  } from "./chunk-A276ZDLP.js";
55
+ import {
56
+ firstLower
57
+ } from "./chunk-4OBNLDTJ.js";
58
+ import {
59
+ firstUpper
60
+ } from "./chunk-EWJJKQIO.js";
56
61
  import {
57
62
  __export
58
63
  } from "./chunk-MLKGABMK.js";
@@ -63,6 +68,7 @@ __export(string_exports, {
63
68
  appearNum: () => appearNum,
64
69
  appearNumSeat: () => appearNumSeat,
65
70
  deComment: () => deComment,
71
+ extractParams: () => extractParams,
66
72
  firstLower: () => firstLower,
67
73
  firstUpper: () => firstUpper,
68
74
  getContent: () => getContent,
@@ -78,6 +84,8 @@ __export(string_exports, {
78
84
  splitUpper: () => splitUpper,
79
85
  startsNum: () => startsNum,
80
86
  toFunction: () => toFunction,
87
+ toFunctionParam: () => toFunctionParam,
88
+ toFunctionParamOptions: () => toFunctionParamOptions,
81
89
  toJSONParse: () => toJSONParse,
82
90
  toJSONSParse: () => toJSONSParse,
83
91
  toJSONSStringify: () => toJSONSStringify,
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
2
 
3
- var _chunkA5UJF6LPcjs = require('./chunk-A5UJF6LP.cjs');
3
+ var _chunkJJ37YIPJcjs = require('./chunk-JJ37YIPJ.cjs');
4
4
 
5
5
 
6
- var _chunkQXK4IUBIcjs = require('./chunk-QXK4IUBI.cjs');
6
+ var _chunkA5UJF6LPcjs = require('./chunk-A5UJF6LP.cjs');
7
7
 
8
8
  // packages/basic/string/toJsons.ts
9
9
  var TYPE_MARKERS = {
@@ -260,7 +260,7 @@ function toJSONSParse(str, context) {
260
260
  case TYPE_MARKERS.SYMBOL:
261
261
  return markerValue.k ? Symbol.for(markerValue.k) : Symbol(markerValue.d);
262
262
  case TYPE_MARKERS.FUNCTION:
263
- return _chunkQXK4IUBIcjs.toFunction.call(void 0, markerValue, key) || function() {
263
+ return _chunkJJ37YIPJcjs.toFunction.call(void 0, markerValue, key) || function() {
264
264
  };
265
265
  case TYPE_MARKERS.NAN:
266
266
  return NaN;
@@ -1,24 +1,20 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkJHV27P2Qcjs = require('./chunk-JHV27P2Q.cjs');
4
+ var _chunkZZKR5C3Ycjs = require('./chunk-ZZKR5C3Y.cjs');
5
5
 
6
6
 
7
7
 
8
+ var _chunkK2XKKEE7cjs = require('./chunk-K2XKKEE7.cjs');
8
9
 
9
10
 
10
- var _chunk3FQKILLZcjs = require('./chunk-3FQKILLZ.cjs');
11
11
 
12
12
 
13
- var _chunkXG44HG5Ncjs = require('./chunk-XG44HG5N.cjs');
14
13
 
14
+ var _chunkENKAUJ2Mcjs = require('./chunk-ENKAUJ2M.cjs');
15
15
 
16
16
 
17
- var _chunkQXK4IUBIcjs = require('./chunk-QXK4IUBI.cjs');
18
-
19
-
20
-
21
- var _chunk4PUYFFPOcjs = require('./chunk-4PUYFFPO.cjs');
17
+ var _chunkHLKHFBMFcjs = require('./chunk-HLKHFBMF.cjs');
22
18
 
23
19
 
24
20
 
@@ -31,13 +27,16 @@ var _chunkJ7S3KBHLcjs = require('./chunk-J7S3KBHL.cjs');
31
27
  var _chunkL7FSHU27cjs = require('./chunk-L7FSHU27.cjs');
32
28
 
33
29
 
34
- var _chunkXWCRGY54cjs = require('./chunk-XWCRGY54.cjs');
35
30
 
36
31
 
37
- var _chunkUEVMS6QDcjs = require('./chunk-UEVMS6QD.cjs');
32
+ var _chunkJJ37YIPJcjs = require('./chunk-JJ37YIPJ.cjs');
38
33
 
39
34
 
40
- var _chunkOQL4GIEJcjs = require('./chunk-OQL4GIEJ.cjs');
35
+ var _chunkXWCRGY54cjs = require('./chunk-XWCRGY54.cjs');
36
+
37
+
38
+
39
+ var _chunk4PUYFFPOcjs = require('./chunk-4PUYFFPO.cjs');
41
40
 
42
41
 
43
42
  var _chunk2H3KVSFAcjs = require('./chunk-2H3KVSFA.cjs');
@@ -55,6 +54,12 @@ var _chunkJR6ZN6QDcjs = require('./chunk-JR6ZN6QD.cjs');
55
54
  var _chunkPW7RP73Jcjs = require('./chunk-PW7RP73J.cjs');
56
55
 
57
56
 
57
+ var _chunkUEVMS6QDcjs = require('./chunk-UEVMS6QD.cjs');
58
+
59
+
60
+ var _chunkOQL4GIEJcjs = require('./chunk-OQL4GIEJ.cjs');
61
+
62
+
58
63
  var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
59
64
 
60
65
  // packages/basic/string/index.ts
@@ -63,26 +68,29 @@ _chunk75ZPJI57cjs.__export.call(void 0, string_exports, {
63
68
  appearNum: () => _chunkOJBZ7UUCcjs.appearNum,
64
69
  appearNumSeat: () => _chunkJR6ZN6QDcjs.appearNumSeat,
65
70
  deComment: () => _chunkXWCRGY54cjs.deComment,
71
+ extractParams: () => _chunkJJ37YIPJcjs.extractParams,
66
72
  firstLower: () => _chunkUEVMS6QDcjs.firstLower,
67
73
  firstUpper: () => _chunkOQL4GIEJcjs.firstUpper,
68
74
  getContent: () => _chunk4PUYFFPOcjs.getContent,
69
75
  getContents: () => _chunk4PUYFFPOcjs.getContents,
70
- getFunctionFormat: () => _chunkQXK4IUBIcjs.getFunctionFormat,
76
+ getFunctionFormat: () => _chunkJJ37YIPJcjs.getFunctionFormat,
71
77
  getImports: () => _chunkHWHYHL6Jcjs.getImports,
72
78
  getImportss: () => _chunkHWHYHL6Jcjs.getImportss,
73
79
  getStartSame: () => _chunkJ7S3KBHLcjs.getStartSame,
74
80
  getStartSames: () => _chunkPW7RP73Jcjs.getStartSames,
75
81
  getStrNunPosit: () => _chunk2H3KVSFAcjs.getStrNunPosit,
76
- serializeCodeBlock: () => _chunk3FQKILLZcjs.serializeCodeBlock,
77
- serializeFunctionRef: () => _chunk3FQKILLZcjs.serializeFunctionRef,
82
+ serializeCodeBlock: () => _chunkENKAUJ2Mcjs.serializeCodeBlock,
83
+ serializeFunctionRef: () => _chunkENKAUJ2Mcjs.serializeFunctionRef,
78
84
  splitUpper: () => _chunkL7FSHU27cjs.splitUpper,
79
85
  startsNum: () => _chunkILJLXJ5Ocjs.startsNum,
80
- toFunction: () => _chunkQXK4IUBIcjs.toFunction,
81
- toJSONParse: () => _chunkJHV27P2Qcjs.toJSONParse,
82
- toJSONSParse: () => _chunk3FQKILLZcjs.toJSONSParse,
83
- toJSONSStringify: () => _chunk3FQKILLZcjs.toJSONSStringify,
84
- toJSONStringify: () => _chunkJHV27P2Qcjs.toJSONStringify,
85
- toStringParse: () => _chunkXG44HG5Ncjs.toStringParse
86
+ toFunction: () => _chunkJJ37YIPJcjs.toFunction,
87
+ toFunctionParam: () => _chunkZZKR5C3Ycjs.toFunctionParam,
88
+ toFunctionParamOptions: () => _chunkZZKR5C3Ycjs.toFunctionParamOptions,
89
+ toJSONParse: () => _chunkK2XKKEE7cjs.toJSONParse,
90
+ toJSONSParse: () => _chunkENKAUJ2Mcjs.toJSONSParse,
91
+ toJSONSStringify: () => _chunkENKAUJ2Mcjs.toJSONSStringify,
92
+ toJSONStringify: () => _chunkK2XKKEE7cjs.toJSONStringify,
93
+ toStringParse: () => _chunkHLKHFBMFcjs.toStringParse
86
94
  });
87
95
 
88
96
 
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkQXK4IUBIcjs = require('./chunk-QXK4IUBI.cjs');
3
+ var _chunkJJ37YIPJcjs = require('./chunk-JJ37YIPJ.cjs');
4
4
 
5
5
  // packages/basic/string/toStringParse.ts
6
6
  var arrayBufferUtils = {
@@ -71,7 +71,7 @@ function toStringParse(str, type, split = ",") {
71
71
  case "boolean":
72
72
  return Boolean(str);
73
73
  case "function":
74
- return _chunkQXK4IUBIcjs.toFunction.call(void 0, str) || function() {
74
+ return _chunkJJ37YIPJcjs.toFunction.call(void 0, str) || function() {
75
75
  };
76
76
  case "undefined":
77
77
  return void 0;
@@ -37,38 +37,6 @@ function extractParams(paramStr) {
37
37
  if (current.trim()) result.push(current.trim());
38
38
  return result;
39
39
  }
40
- function toFunction(str, key) {
41
- try {
42
- const obj = getFunctionFormat(str);
43
- if (!_optionalChain([obj, 'optionalAccess', _2 => _2.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 ? "*" : ""} ${_nullishCoalesce(_nullishCoalesce(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 ? "*" : ""} ${_nullishCoalesce(_nullishCoalesce(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
40
  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
41
  function getFunctionFormat(v) {
74
42
  if (!v) return;
@@ -110,33 +78,72 @@ function getFunctionFormat(v) {
110
78
  let name = "";
111
79
  let param = "";
112
80
  let body = "";
81
+ let isArrow = false;
82
+ let arrowBody = "";
113
83
  if (funcParams !== void 0) {
114
84
  isGenerator = funcGenerator === "*";
115
85
  name = funcName || "";
116
86
  param = funcParams;
117
87
  body = blockBody || exprBody || "";
118
88
  } else if (methodParams !== void 0) {
119
- isGenerator = _optionalChain([methodGenerator, 'optionalAccess', _3 => _3.includes, 'call', _4 => _4("*")]) || false;
89
+ isGenerator = _optionalChain([methodGenerator, 'optionalAccess', _2 => _2.includes, 'call', _3 => _3("*")]) || false;
120
90
  name = methodName || "";
121
91
  param = methodParams;
122
92
  body = blockBody || exprBody || "";
123
93
  } else if (arrowParenParams !== void 0 || arrowSingleParam !== void 0) {
94
+ isArrow = true;
124
95
  param = arrowParenParams || arrowSingleParam || "";
125
96
  body = blockBody || exprBody || "";
97
+ arrowBody = body.trim();
126
98
  if (!blockBody && !/^\s*return\b/.test(body)) {
127
99
  body = `return ${body}`;
128
100
  }
129
101
  }
130
102
  return {
103
+ isArrow,
131
104
  isAsync,
132
105
  isGenerator,
133
106
  ...name && { name },
134
107
  param: param.trim(),
135
- body: body.trim()
108
+ body: body.trim(),
109
+ arrowBody
136
110
  };
137
111
  }
112
+ function toFunction(str, key) {
113
+ try {
114
+ const obj = getFunctionFormat(str);
115
+ if (!_optionalChain([obj, 'optionalAccess', _4 => _4.body])) return void 0;
116
+ const params = obj.param ? extractParams(obj.param) : [];
117
+ if (params.length > 1e3) {
118
+ throw new Error("Too many parameters (max: 1000)");
119
+ }
120
+ if (obj.isAsync) {
121
+ try {
122
+ const fullFunction = `async function${obj.isGenerator ? "*" : ""} ${_nullishCoalesce(_nullishCoalesce(obj.name, () => ( key)), () => ( ""))} (${obj.param}) { ${obj.body} }`;
123
+ return new Function(`return ${fullFunction}`)();
124
+ } catch (error) {
125
+ const fullFunction = `async function${obj.isGenerator ? "*" : ""} (${obj.param}) { ${obj.body} }`;
126
+ return new Function(`return ${fullFunction}`)();
127
+ }
128
+ } else {
129
+ try {
130
+ const fullFunction = `function${obj.isGenerator ? "*" : ""} ${_nullishCoalesce(_nullishCoalesce(obj.name, () => ( key)), () => ( ""))}(${obj.param}) { ${obj.body} }`;
131
+ return new Function(`return (${fullFunction})`)();
132
+ } catch (error) {
133
+ return new Function(...params, obj.body);
134
+ }
135
+ }
136
+ } catch (error) {
137
+ console.error("Function creation failed:", {
138
+ input: str.slice(0, 100),
139
+ error
140
+ });
141
+ return void 0;
142
+ }
143
+ }
144
+
138
145
 
139
146
 
140
147
 
141
148
 
142
- exports.toFunction = toFunction; exports.getFunctionFormat = getFunctionFormat;
149
+ exports.extractParams = extractParams; exports.getFunctionFormat = getFunctionFormat; exports.toFunction = toFunction;
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkQXK4IUBIcjs = require('./chunk-QXK4IUBI.cjs');
3
+ var _chunkJJ37YIPJcjs = require('./chunk-JJ37YIPJ.cjs');
4
4
 
5
5
  // packages/basic/string/toJson.ts
6
6
  function toJSONStringify(obj, space) {
@@ -33,7 +33,7 @@ function toJSONParse(str, reviver) {
33
33
  case "symbol":
34
34
  return Symbol(value.value);
35
35
  case "function":
36
- return _chunkQXK4IUBIcjs.toFunction.call(void 0, value.value) || value;
36
+ return _chunkJJ37YIPJcjs.toFunction.call(void 0, value.value) || value;
37
37
  case "undefined":
38
38
  return void 0;
39
39
  case "Date":
@@ -1,9 +1,9 @@
1
- import {
2
- object_exports
3
- } from "./chunk-PFTTRHAB.js";
4
1
  import {
5
2
  string_exports
6
- } from "./chunk-BT2SXUJY.js";
3
+ } from "./chunk-BUMAKEB5.js";
4
+ import {
5
+ object_exports
6
+ } from "./chunk-7M7ORCKS.js";
7
7
  import {
8
8
  array_exports
9
9
  } from "./chunk-PVXQ2H5H.js";
@@ -37,38 +37,6 @@ function extractParams(paramStr) {
37
37
  if (current.trim()) result.push(current.trim());
38
38
  return result;
39
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
40
  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
41
  function getFunctionFormat(v) {
74
42
  if (!v) return;
@@ -110,6 +78,8 @@ function getFunctionFormat(v) {
110
78
  let name = "";
111
79
  let param = "";
112
80
  let body = "";
81
+ let isArrow = false;
82
+ let arrowBody = "";
113
83
  if (funcParams !== void 0) {
114
84
  isGenerator = funcGenerator === "*";
115
85
  name = funcName || "";
@@ -121,22 +91,59 @@ function getFunctionFormat(v) {
121
91
  param = methodParams;
122
92
  body = blockBody || exprBody || "";
123
93
  } else if (arrowParenParams !== void 0 || arrowSingleParam !== void 0) {
94
+ isArrow = true;
124
95
  param = arrowParenParams || arrowSingleParam || "";
125
96
  body = blockBody || exprBody || "";
97
+ arrowBody = body.trim();
126
98
  if (!blockBody && !/^\s*return\b/.test(body)) {
127
99
  body = `return ${body}`;
128
100
  }
129
101
  }
130
102
  return {
103
+ isArrow,
131
104
  isAsync,
132
105
  isGenerator,
133
106
  ...name && { name },
134
107
  param: param.trim(),
135
- body: body.trim()
108
+ body: body.trim(),
109
+ arrowBody
136
110
  };
137
111
  }
112
+ function toFunction(str, key) {
113
+ try {
114
+ const obj = getFunctionFormat(str);
115
+ if (!obj?.body) return void 0;
116
+ const params = obj.param ? extractParams(obj.param) : [];
117
+ if (params.length > 1e3) {
118
+ throw new Error("Too many parameters (max: 1000)");
119
+ }
120
+ if (obj.isAsync) {
121
+ try {
122
+ const fullFunction = `async function${obj.isGenerator ? "*" : ""} ${obj.name ?? key ?? ""} (${obj.param}) { ${obj.body} }`;
123
+ return new Function(`return ${fullFunction}`)();
124
+ } catch (error) {
125
+ const fullFunction = `async function${obj.isGenerator ? "*" : ""} (${obj.param}) { ${obj.body} }`;
126
+ return new Function(`return ${fullFunction}`)();
127
+ }
128
+ } else {
129
+ try {
130
+ const fullFunction = `function${obj.isGenerator ? "*" : ""} ${obj.name ?? key ?? ""}(${obj.param}) { ${obj.body} }`;
131
+ return new Function(`return (${fullFunction})`)();
132
+ } catch (error) {
133
+ return new Function(...params, obj.body);
134
+ }
135
+ }
136
+ } catch (error) {
137
+ console.error("Function creation failed:", {
138
+ input: str.slice(0, 100),
139
+ error
140
+ });
141
+ return void 0;
142
+ }
143
+ }
138
144
 
139
145
  export {
140
- toFunction,
141
- getFunctionFormat
146
+ extractParams,
147
+ getFunctionFormat,
148
+ toFunction
142
149
  };
@@ -0,0 +1,129 @@
1
+ import {
2
+ extractParams,
3
+ getFunctionFormat
4
+ } from "./chunk-Q6BNW3MO.js";
5
+
6
+ // packages/basic/string/toFunctionParam.ts
7
+ function buildFunctionString(obj) {
8
+ const { isAsync, isGenerator, param, body } = obj;
9
+ const funcName = obj.name || "";
10
+ const funcSignature = `${isAsync ? "async " : ""}${isGenerator ? "*" : ""}function${funcName ? ` ${funcName}` : ""}`;
11
+ return `${funcSignature}(${param}) { ${body} }`;
12
+ }
13
+ function createSimpleFunction(obj) {
14
+ return new Function(`return ${buildFunctionString(obj)}`)();
15
+ }
16
+ function createFunctionWithClosure(obj, externalParams) {
17
+ const externalKeys = Object.keys(externalParams);
18
+ if (externalKeys.length === 0) {
19
+ return createSimpleFunction(obj);
20
+ }
21
+ try {
22
+ const factory = new Function(
23
+ ...externalKeys,
24
+ `return ${buildFunctionString(obj)};`
25
+ );
26
+ return factory(...externalKeys.map((k) => externalParams[k]));
27
+ } catch (error) {
28
+ const { param, body } = obj;
29
+ const funcParams = param ? extractParams(param) : [];
30
+ const allParams = [...funcParams, ...externalKeys];
31
+ const closure = new Function(...allParams, body);
32
+ return function(...args) {
33
+ return closure(
34
+ ...args,
35
+ ...externalKeys.map((k) => externalParams[k])
36
+ );
37
+ };
38
+ }
39
+ }
40
+ function createFunctionWithoutClosure(obj, externalParams) {
41
+ const funcParams = obj.param ? extractParams(obj.param) : [];
42
+ const externalKeys = Object.keys(externalParams);
43
+ const baseFunc = createSimpleFunction(obj);
44
+ return function(...args) {
45
+ const context = {};
46
+ externalKeys.forEach((k) => {
47
+ context[k] = externalParams[k];
48
+ });
49
+ funcParams.forEach((paramName, index) => {
50
+ const cleanParam = paramName.split("=")[0].trim();
51
+ context[cleanParam] = args[index];
52
+ });
53
+ return baseFunc.call(context, ...args);
54
+ };
55
+ }
56
+ function toFunctionParam(str, externalParams) {
57
+ try {
58
+ const obj = getFunctionFormat(str);
59
+ if (!obj?.body) return void 0;
60
+ if (obj.param) {
61
+ const paramCount = extractParams(obj.param).length;
62
+ if (paramCount > 1e3) {
63
+ console.warn("Too many parameters, limiting to 1000");
64
+ return void 0;
65
+ }
66
+ }
67
+ if (externalParams && Object.keys(externalParams).length > 0) {
68
+ return createFunctionWithClosure(obj, externalParams);
69
+ } else {
70
+ return createSimpleFunction(obj);
71
+ }
72
+ } catch (error) {
73
+ console.error("Function creation failed:", error);
74
+ return void 0;
75
+ }
76
+ }
77
+ function toFunctionParamOptions(str, externalParams, options) {
78
+ try {
79
+ const obj = getFunctionFormat(str);
80
+ if (!obj?.body) return void 0;
81
+ const opts = {
82
+ useClosure: true,
83
+ // 默认使用闭包方式(性能更好)
84
+ strictMode: true,
85
+ context: {},
86
+ paramDefaults: {},
87
+ bindThis: false,
88
+ ...options
89
+ };
90
+ let functionBody = obj.body;
91
+ if (opts.paramDefaults && Object.keys(opts.paramDefaults).length > 0) {
92
+ const defaultsCode = Object.entries(opts.paramDefaults).map(
93
+ ([name, value]) => `if (${name} === undefined) ${name} = ${JSON.stringify(
94
+ value
95
+ )};`
96
+ ).join(" ");
97
+ functionBody = defaultsCode + " " + functionBody;
98
+ }
99
+ if (opts.strictMode) {
100
+ functionBody = `'use strict'; ${functionBody}`;
101
+ }
102
+ const funcObj = { ...obj, body: functionBody };
103
+ if (opts.name && !funcObj.name) {
104
+ funcObj.name = opts.name;
105
+ }
106
+ let result;
107
+ if (externalParams && Object.keys(externalParams).length > 0) {
108
+ if (opts.useClosure) {
109
+ result = createFunctionWithClosure(funcObj, externalParams);
110
+ } else {
111
+ result = createFunctionWithoutClosure(funcObj, externalParams);
112
+ }
113
+ } else {
114
+ result = createSimpleFunction(funcObj);
115
+ }
116
+ if (opts.bindThis && opts.context && Object.keys(opts.context).length > 0) {
117
+ return result.bind(opts.context);
118
+ }
119
+ return result;
120
+ } catch (error) {
121
+ console.error("Enhanced function creation failed:", error);
122
+ return void 0;
123
+ }
124
+ }
125
+
126
+ export {
127
+ toFunctionParam,
128
+ toFunctionParamOptions
129
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  toFunction
3
- } from "./chunk-7O4MJOHM.js";
3
+ } from "./chunk-Q6BNW3MO.js";
4
4
 
5
5
  // packages/basic/string/toJson.ts
6
6
  function toJSONStringify(obj, space) {
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkFJ5PJYIYcjs = require('./chunk-FJ5PJYIY.cjs');
3
+ var _chunkG7IWN7T3cjs = require('./chunk-G7IWN7T3.cjs');
4
4
 
5
5
 
6
- var _chunkLMKPAAY6cjs = require('./chunk-LMKPAAY6.cjs');
6
+ var _chunkKZCLX66Dcjs = require('./chunk-KZCLX66D.cjs');
7
7
 
8
8
 
9
9
  var _chunk65O7KWP4cjs = require('./chunk-65O7KWP4.cjs');
@@ -15,8 +15,8 @@ var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
15
15
  var basic_exports = {};
16
16
  _chunk75ZPJI57cjs.__export.call(void 0, basic_exports, {
17
17
  array: () => _chunk65O7KWP4cjs.array_exports,
18
- object: () => _chunkFJ5PJYIYcjs.object_exports,
19
- string: () => _chunkLMKPAAY6cjs.string_exports
18
+ object: () => _chunkKZCLX66Dcjs.object_exports,
19
+ string: () => _chunkG7IWN7T3cjs.string_exports
20
20
  });
21
21
 
22
22