@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.
- package/array.js +4 -4
- package/component.js +2 -2
- package/dist/cjs/array.js +3 -3
- package/dist/cjs/component.js +1 -1
- package/dist/cjs/object.js +39 -63
- package/dist/esm/array.js +122 -0
- package/dist/esm/component.js +241 -0
- package/dist/esm/cookie.js +60 -0
- package/dist/esm/env.js +12 -0
- package/dist/esm/function.js +61 -0
- package/dist/esm/globals.js +10 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/key.js +13 -0
- package/dist/esm/log.js +15 -0
- package/dist/esm/node.js +15 -0
- package/dist/esm/object.js +665 -0
- package/dist/esm/string.js +124 -0
- package/dist/esm/tags.js +145 -0
- package/dist/esm/types.js +64 -0
- package/object.js +67 -113
- package/package.json +6 -6
|
@@ -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,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";
|
package/dist/esm/key.js
ADDED
package/dist/esm/log.js
ADDED
|
@@ -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
|
+
};
|
package/dist/esm/node.js
ADDED
|
@@ -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
|
+
};
|