@domql/utils 2.31.0 → 2.31.2

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.
@@ -21,6 +21,7 @@ __export(function_exports, {
21
21
  cloneFunction: () => cloneFunction,
22
22
  debounce: () => debounce,
23
23
  debounceOnContext: () => debounceOnContext,
24
+ getContextFunction: () => getContextFunction,
24
25
  isStringFunction: () => isStringFunction,
25
26
  memoize: () => memoize
26
27
  });
@@ -77,3 +78,7 @@ function cloneFunction(fn, win = window) {
77
78
  }
78
79
  return temp;
79
80
  }
81
+ function getContextFunction(fnKey) {
82
+ var _a, _b, _c, _d;
83
+ return ((_a = this.context.utils) == null ? void 0 : _a[fnKey]) || ((_b = this.context.functions) == null ? void 0 : _b[fnKey]) || ((_c = this.context.methods) == null ? void 0 : _c[fnKey]) || ((_d = this.context.snippets) == null ? void 0 : _d[fnKey]);
84
+ }
@@ -50,10 +50,15 @@ function cloneFunction(fn, win = window) {
50
50
  }
51
51
  return temp;
52
52
  }
53
+ function getContextFunction(fnKey) {
54
+ var _a, _b, _c, _d;
55
+ return ((_a = this.context.utils) == null ? void 0 : _a[fnKey]) || ((_b = this.context.functions) == null ? void 0 : _b[fnKey]) || ((_c = this.context.methods) == null ? void 0 : _c[fnKey]) || ((_d = this.context.snippets) == null ? void 0 : _d[fnKey]);
56
+ }
53
57
  export {
54
58
  cloneFunction,
55
59
  debounce,
56
60
  debounceOnContext,
61
+ getContextFunction,
57
62
  isStringFunction,
58
63
  memoize
59
64
  };
package/function.js CHANGED
@@ -13,7 +13,7 @@
13
13
  * const debouncedFunction = debounce(this, myFunction, 500);
14
14
  * window.addEventListener('resize', debouncedFunction);
15
15
  */
16
- export function debounce (func, wait, immediate) {
16
+ export function debounce(func, wait, immediate) {
17
17
  let timeout
18
18
  return function () {
19
19
  const context = this
@@ -53,7 +53,7 @@ export const debounceOnContext = (element, func, timeout = 300) => {
53
53
  }
54
54
  }
55
55
 
56
- export const memoize = fn => {
56
+ export const memoize = (fn) => {
57
57
  const cache = {}
58
58
  return (...args) => {
59
59
  const n = args[0]
@@ -67,7 +67,7 @@ export const memoize = fn => {
67
67
  }
68
68
  }
69
69
 
70
- export const isStringFunction = inputString => {
70
+ export const isStringFunction = (inputString) => {
71
71
  // Regular expression to match both regular and arrow function declarations
72
72
  const functionRegex = /^((function\s*\([^)]*\)\s*\{[^}]*\})|(\([^)]*\)\s*=>))/
73
73
 
@@ -75,7 +75,7 @@ export const isStringFunction = inputString => {
75
75
  return functionRegex.test(inputString)
76
76
  }
77
77
 
78
- export function cloneFunction (fn, win = window) {
78
+ export function cloneFunction(fn, win = window) {
79
79
  const temp = function () {
80
80
  return fn.apply(win, arguments)
81
81
  }
@@ -88,3 +88,12 @@ export function cloneFunction (fn, win = window) {
88
88
  }
89
89
  return temp
90
90
  }
91
+
92
+ export function getContextFunction(fnKey) {
93
+ return (
94
+ this.context.utils?.[fnKey] ||
95
+ this.context.functions?.[fnKey] ||
96
+ this.context.methods?.[fnKey] ||
97
+ this.context.snippets?.[fnKey]
98
+ )
99
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.31.0",
3
+ "version": "2.31.2",
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": "dd5c64895320d678f28ca585c9fd4e4550a483cd",
27
+ "gitHead": "c7d23e63ab53e68a7c670f45e94cb2c7d514262e",
28
28
  "devDependencies": {
29
29
  "@babel/core": "^7.27.1"
30
30
  }