@domql/utils 2.5.119 → 2.5.123

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.
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var function_exports = {};
20
20
  __export(function_exports, {
21
+ cloneFunction: () => cloneFunction,
21
22
  debounce: () => debounce,
22
23
  debounceOnContext: () => debounceOnContext,
23
24
  isStringFunction: () => isStringFunction,
@@ -67,3 +68,14 @@ const isStringFunction = (inputString) => {
67
68
  const functionRegex = /^((function\s*\([^)]*\)\s*\{[^}]*\})|(\([^)]*\)\s*=>))/;
68
69
  return functionRegex.test(inputString);
69
70
  };
71
+ function cloneFunction(fn, win = window) {
72
+ const temp = function() {
73
+ return fn.apply(win, arguments);
74
+ };
75
+ for (const key in fn) {
76
+ if (Object.hasOwnProperty.call(fn, key)) {
77
+ temp[key] = fn[key];
78
+ }
79
+ }
80
+ return temp;
81
+ }
@@ -61,6 +61,7 @@ var import_types = require("./types.js");
61
61
  var import_array = require("./array.js");
62
62
  var import_string = require("./string.js");
63
63
  var import_node = require("./node.js");
64
+ var import_function = require("./function.js");
64
65
  const exec = (param, element, state, context) => {
65
66
  if ((0, import_types.isFunction)(param)) {
66
67
  return param(
@@ -172,6 +173,8 @@ const deepCloneWithExtend = (obj, excludeFrom = ["node"], options = {}) => {
172
173
  continue;
173
174
  if ((0, import_types.isObjectLike)(objProp)) {
174
175
  o[prop] = deepCloneWithExtend(objProp, excludeFrom, options);
176
+ } else if ((0, import_types.isFunction)(objProp) && options.window) {
177
+ o[prop] = (0, import_function.cloneFunction)(objProp, options.window);
175
178
  } else
176
179
  o[prop] = objProp;
177
180
  }
package/function.js CHANGED
@@ -71,3 +71,17 @@ export const isStringFunction = inputString => {
71
71
  // Use the regex to test if the inputString matches the function pattern
72
72
  return functionRegex.test(inputString)
73
73
  }
74
+
75
+ export function cloneFunction (fn, win = window) {
76
+ const temp = function () {
77
+ return fn.apply(win, arguments)
78
+ }
79
+
80
+ // Copy properties from original function
81
+ for (const key in fn) {
82
+ if (Object.hasOwnProperty.call(fn, key)) {
83
+ temp[key] = fn[key]
84
+ }
85
+ }
86
+ return temp
87
+ }
package/object.js CHANGED
@@ -5,6 +5,7 @@ import { isFunction, isObjectLike, isObject, isArray, isString, is, isUndefined,
5
5
  import { mergeAndCloneIfArray, mergeArray } from './array.js'
6
6
  import { stringIncludesAny } from './string.js'
7
7
  import { isDOMNode } from './node.js'
8
+ import { cloneFunction } from './function.js'
8
9
 
9
10
  export const exec = (param, element, state, context) => {
10
11
  if (isFunction(param)) {
@@ -176,6 +177,8 @@ export const deepCloneWithExtend = (obj, excludeFrom = ['node'], options = {}) =
176
177
  // queueMicrotask(() => {
177
178
  o[prop] = deepCloneWithExtend(objProp, excludeFrom, options)
178
179
  // })
180
+ } else if (isFunction(objProp) && options.window) {
181
+ o[prop] = cloneFunction(objProp, options.window)
179
182
  } else o[prop] = objProp
180
183
  }
181
184
  return o
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.5.119",
3
+ "version": "2.5.123",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
@@ -23,7 +23,7 @@
23
23
  "build": "yarn build:cjs",
24
24
  "prepublish": "rimraf -I dist && yarn build && yarn copy:package:cjs"
25
25
  },
26
- "gitHead": "930d02cd05b1fa9cbfe3da9b1eea3f1baafdab6b",
26
+ "gitHead": "6dd041deb89bc2ebfa1f5ee9360d563df60eca13",
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.12.0"
29
29
  }