@domql/utils 2.5.156 → 2.5.161

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.
@@ -0,0 +1,61 @@
1
+ function debounce(func, wait, immediate) {
2
+ let timeout;
3
+ return function() {
4
+ const context = this;
5
+ const args = arguments;
6
+ const later = function() {
7
+ timeout = null;
8
+ if (!immediate)
9
+ func.apply(context, args);
10
+ };
11
+ const callNow = immediate && !timeout;
12
+ clearTimeout(timeout);
13
+ timeout = setTimeout(later, wait);
14
+ if (callNow)
15
+ func.apply(context, args);
16
+ };
17
+ }
18
+ const debounceOnContext = (element, func, timeout = 300) => {
19
+ let timer;
20
+ return (...args) => {
21
+ clearTimeout(timer);
22
+ timer = setTimeout(() => {
23
+ func.apply(element, args);
24
+ }, timeout);
25
+ };
26
+ };
27
+ const memoize = (fn) => {
28
+ const cache = {};
29
+ return (...args) => {
30
+ const n = args[0];
31
+ if (n in cache) {
32
+ return cache[n];
33
+ } else {
34
+ const result = fn(n);
35
+ cache[n] = result;
36
+ return result;
37
+ }
38
+ };
39
+ };
40
+ const isStringFunction = (inputString) => {
41
+ const functionRegex = /^((function\s*\([^)]*\)\s*\{[^}]*\})|(\([^)]*\)\s*=>))/;
42
+ return functionRegex.test(inputString);
43
+ };
44
+ function cloneFunction(fn, win = window) {
45
+ const temp = function() {
46
+ return fn.apply(win, arguments);
47
+ };
48
+ for (const key in fn) {
49
+ if (Object.hasOwnProperty.call(fn, key)) {
50
+ temp[key] = fn[key];
51
+ }
52
+ }
53
+ return temp;
54
+ }
55
+ export {
56
+ cloneFunction,
57
+ debounce,
58
+ debounceOnContext,
59
+ isStringFunction,
60
+ memoize
61
+ };
@@ -0,0 +1,10 @@
1
+ const global = globalThis;
2
+ const self = globalThis;
3
+ const window = globalThis;
4
+ const document = window.document;
5
+ export {
6
+ document,
7
+ global,
8
+ self,
9
+ window
10
+ };
@@ -0,0 +1,13 @@
1
+ export * from "./key.js";
2
+ export * from "./env.js";
3
+ export * from "./types.js";
4
+ export * from "./object.js";
5
+ export * from "./function.js";
6
+ export * from "./array.js";
7
+ export * from "./node.js";
8
+ export * from "./log.js";
9
+ export * from "./string.js";
10
+ export * from "./globals.js";
11
+ export * from "./cookie.js";
12
+ export * from "./tags.js";
13
+ export * from "./component.js";
@@ -0,0 +1,13 @@
1
+ const generateKey = function() {
2
+ let index = 0;
3
+ function newId() {
4
+ index++;
5
+ return index;
6
+ }
7
+ return newId;
8
+ }();
9
+ const createSnapshotId = generateKey;
10
+ export {
11
+ createSnapshotId,
12
+ generateKey
13
+ };
@@ -0,0 +1,15 @@
1
+ const logIf = (bool, ...arg) => {
2
+ if (bool)
3
+ arg.map((v) => console.log(v));
4
+ };
5
+ const logGroupIf = (bool, key, ...arg) => {
6
+ if (bool) {
7
+ console.group(key);
8
+ arg.map((v) => console.log(v));
9
+ console.groupEnd(key);
10
+ }
11
+ };
12
+ export {
13
+ logGroupIf,
14
+ logIf
15
+ };
@@ -0,0 +1,15 @@
1
+ import { window } from "./globals";
2
+ const isNode = (obj) => {
3
+ return (typeof Node === "object" ? obj instanceof window.Node : obj && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string") || false;
4
+ };
5
+ const isHtmlElement = (obj) => {
6
+ return (typeof HTMLElement === "object" ? obj instanceof window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string") || false;
7
+ };
8
+ const isDOMNode = (obj) => {
9
+ return typeof window !== "undefined" && (obj instanceof window.Node || obj instanceof window.Window || obj === window || obj === document);
10
+ };
11
+ export {
12
+ isDOMNode,
13
+ isHtmlElement,
14
+ isNode
15
+ };