@domql/utils 2.27.16 → 2.28.1
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/dist/cjs/object.js +17 -6
- package/dist/esm/object.js +17 -6
- package/object.js +35 -6
- package/package.json +2 -2
package/dist/cjs/object.js
CHANGED
|
@@ -66,12 +66,23 @@ var import_node = require("./node.js");
|
|
|
66
66
|
var import_env = require("./env.js");
|
|
67
67
|
const exec = (param, element, state, context) => {
|
|
68
68
|
if ((0, import_types.isFunction)(param)) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
try {
|
|
70
|
+
const result = param.call(
|
|
71
|
+
element,
|
|
72
|
+
element,
|
|
73
|
+
state || element.state,
|
|
74
|
+
context || element.context
|
|
75
|
+
);
|
|
76
|
+
if (result && typeof result.then === "function") {
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
} catch (e) {
|
|
81
|
+
if ((0, import_env.isNotProduction)()) {
|
|
82
|
+
console.log(param);
|
|
83
|
+
console.warn("Error executing function", e);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
75
86
|
}
|
|
76
87
|
return param;
|
|
77
88
|
};
|
package/dist/esm/object.js
CHANGED
|
@@ -35,12 +35,23 @@ import { isDOMNode } from "./node.js";
|
|
|
35
35
|
import { isNotProduction } from "./env.js";
|
|
36
36
|
const exec = (param, element, state, context) => {
|
|
37
37
|
if (isFunction(param)) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
try {
|
|
39
|
+
const result = param.call(
|
|
40
|
+
element,
|
|
41
|
+
element,
|
|
42
|
+
state || element.state,
|
|
43
|
+
context || element.context
|
|
44
|
+
);
|
|
45
|
+
if (result && typeof result.then === "function") {
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (isNotProduction()) {
|
|
51
|
+
console.log(param);
|
|
52
|
+
console.warn("Error executing function", e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
44
55
|
}
|
|
45
56
|
return param;
|
|
46
57
|
};
|
package/object.js
CHANGED
|
@@ -17,14 +17,43 @@ import { stringIncludesAny } from './string.js'
|
|
|
17
17
|
import { isDOMNode } from './node.js'
|
|
18
18
|
import { isNotProduction } from './env.js'
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Executes a function with the specified context and parameters.
|
|
22
|
+
* Handles both synchronous and asynchronous functions.
|
|
23
|
+
*
|
|
24
|
+
* - When called in an async context (with await), it fully resolves promises
|
|
25
|
+
* - When called in a sync context, it returns sync results directly and handles promises appropriately
|
|
26
|
+
*
|
|
27
|
+
* @param {Function|any} param - The function to execute or value to return
|
|
28
|
+
* @param {Object} element - The element to use as 'this' context
|
|
29
|
+
* @param {Object} state - The state to pass to the function
|
|
30
|
+
* @param {Object} context - The context to pass to the function
|
|
31
|
+
* @returns {any|Promise} - The result or a Promise to the result
|
|
32
|
+
*/
|
|
20
33
|
export const exec = (param, element, state, context) => {
|
|
21
34
|
if (isFunction(param)) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
try {
|
|
36
|
+
// Call the function with the specified context and parameters
|
|
37
|
+
const result = param.call(
|
|
38
|
+
element,
|
|
39
|
+
element,
|
|
40
|
+
state || element.state,
|
|
41
|
+
context || element.context
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
// Handle promises
|
|
45
|
+
if (result && typeof result.then === 'function') {
|
|
46
|
+
// This magic allows the function to be awaited if called with await
|
|
47
|
+
// but still work reasonably when called without await
|
|
48
|
+
return result
|
|
49
|
+
}
|
|
50
|
+
return result
|
|
51
|
+
} catch (e) {
|
|
52
|
+
if (isNotProduction()) {
|
|
53
|
+
console.log(param)
|
|
54
|
+
console.warn('Error executing function', e)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
28
57
|
}
|
|
29
58
|
return param
|
|
30
59
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.28.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"build": "npx rimraf -I dist; npm run build:cjs; npm run build:esm",
|
|
25
25
|
"prepublish": "npm run build; npm run copy:package:cjs"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "371cc070cdca345fcd7ea73558d336a03c847825",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@babel/core": "^7.26.0"
|
|
30
30
|
}
|