@ocavue/utils 0.4.0 → 0.5.0
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/index.d.ts +77 -15
- package/dist/index.js +16 -1
- package/package.json +11 -5
- package/dist/_tsup-dts-rollup.d.ts +0 -105
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
declare function isObject(value: unknown): value is Record<string | symbol | number, unknown>;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if the given DOM node is an Element.
|
|
5
|
+
*/
|
|
6
|
+
declare function isElement(node: Node): node is Element;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if the given DOM node is a Text node.
|
|
9
|
+
*/
|
|
10
|
+
declare function isTextNode(node: Node): node is Text;
|
|
11
|
+
/**
|
|
12
|
+
* Checks if the given DOM node is an HTMLElement.
|
|
13
|
+
*/
|
|
14
|
+
declare function isHTMLElement(node: Node): node is HTMLElement;
|
|
15
|
+
/**
|
|
16
|
+
* Checks if the given DOM node is an SVGElement.
|
|
17
|
+
*/
|
|
18
|
+
declare function isSVGElement(node: Node): node is SVGElement;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if the given DOM node is an MathMLElement.
|
|
21
|
+
*/
|
|
22
|
+
declare function isMathMLElement(node: Node): node is MathMLElement;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the given DOM node is a Document.
|
|
25
|
+
*/
|
|
26
|
+
declare function isDocument(node: Node): node is Document;
|
|
27
|
+
/**
|
|
28
|
+
* Checks if the given DOM node is a DocumentFragment.
|
|
29
|
+
*/
|
|
30
|
+
declare function isDocumentFragment(node: Node): node is DocumentFragment;
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the given DOM node is a ShadowRoot.
|
|
33
|
+
*/
|
|
34
|
+
declare function isShadowRoot(node: Node): node is ShadowRoot;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if an unknown value is likely a DOM node.
|
|
37
|
+
*/
|
|
38
|
+
declare function isNodeLike(value: unknown): value is Node;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if an unknown value is likely a DOM element.
|
|
41
|
+
*/
|
|
42
|
+
declare function isElementLike(value: unknown): value is Element;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if the given value is likely a Window object.
|
|
45
|
+
*/
|
|
46
|
+
declare function isWindowLike(value: unknown): value is Window;
|
|
47
|
+
/**
|
|
48
|
+
* Gets the window object for the given target or the global window object if no
|
|
49
|
+
* target is provided.
|
|
50
|
+
*/
|
|
51
|
+
declare function getWindow(target?: Node | ShadowRoot | Document | null): Window & typeof globalThis;
|
|
52
|
+
/**
|
|
53
|
+
* Gets the document for the given target or the global document if no target is
|
|
54
|
+
* provided.
|
|
55
|
+
*/
|
|
56
|
+
declare function getDocument(target?: Element | Window | Node | Document | null): Document;
|
|
57
|
+
/**
|
|
58
|
+
* Gets a reference to the root node of the document based on the given target.
|
|
59
|
+
*/
|
|
60
|
+
declare function getDocumentElement(target?: Element | Node | Window | Document | null): HTMLElement;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Creates a function that will only execute the provided function once.
|
|
64
|
+
* Subsequent calls will return the cached result from the first execution.
|
|
65
|
+
*
|
|
66
|
+
* @param fn The function to execute once
|
|
67
|
+
* @returns A function that will only execute the provided function once
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const getValue = once(() => expensiveOperation())
|
|
71
|
+
* getValue() // executes expensiveOperation
|
|
72
|
+
* getValue() // returns cached result
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare function once<T>(fn: () => T): () => T;
|
|
76
|
+
|
|
77
|
+
export { getDocument, getDocumentElement, getWindow, isDocument, isDocumentFragment, isElement, isElementLike, isHTMLElement, isMathMLElement, isNodeLike, isObject, isSVGElement, isShadowRoot, isTextNode, isWindowLike, once };
|
package/dist/index.js
CHANGED
|
@@ -66,6 +66,20 @@ function getDocument(target) {
|
|
|
66
66
|
function getDocumentElement(target) {
|
|
67
67
|
return getDocument(target).documentElement;
|
|
68
68
|
}
|
|
69
|
+
|
|
70
|
+
// src/once.ts
|
|
71
|
+
function once(fn) {
|
|
72
|
+
let called = false;
|
|
73
|
+
let result;
|
|
74
|
+
return () => {
|
|
75
|
+
if (!called) {
|
|
76
|
+
result = fn();
|
|
77
|
+
called = true;
|
|
78
|
+
fn = void 0;
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
69
83
|
export {
|
|
70
84
|
getDocument,
|
|
71
85
|
getDocumentElement,
|
|
@@ -81,5 +95,6 @@ export {
|
|
|
81
95
|
isSVGElement,
|
|
82
96
|
isShadowRoot,
|
|
83
97
|
isTextNode,
|
|
84
|
-
isWindowLike
|
|
98
|
+
isWindowLike,
|
|
99
|
+
once
|
|
85
100
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocavue/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "ocavue <ocavue@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,14 +36,15 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@ocavue/
|
|
41
|
-
"@
|
|
39
|
+
"@ocavue/eslint-config": "^3.1.1",
|
|
40
|
+
"@ocavue/tsconfig": "^0.3.7",
|
|
41
|
+
"@size-limit/preset-small-lib": "^11.2.0",
|
|
42
42
|
"@types/node": "^20.17.27",
|
|
43
43
|
"eslint": "^9.23.0",
|
|
44
44
|
"jsdom": "^26.0.0",
|
|
45
45
|
"prettier": "^3.5.3",
|
|
46
|
-
"
|
|
46
|
+
"size-limit": "^11.2.0",
|
|
47
|
+
"tsup": "^8.5.0",
|
|
47
48
|
"typescript": "^5.7.2",
|
|
48
49
|
"vite": "^6.0.12",
|
|
49
50
|
"vitest": "^3.0.9"
|
|
@@ -51,6 +52,11 @@
|
|
|
51
52
|
"publishConfig": {
|
|
52
53
|
"access": "public"
|
|
53
54
|
},
|
|
55
|
+
"size-limit": [
|
|
56
|
+
{
|
|
57
|
+
"path": "dist/index.js"
|
|
58
|
+
}
|
|
59
|
+
],
|
|
54
60
|
"renovate": {
|
|
55
61
|
"extends": [
|
|
56
62
|
"github>ocavue/config-renovate"
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gets the document for the given target or the global document if no target is
|
|
3
|
-
* provided.
|
|
4
|
-
*/
|
|
5
|
-
declare function getDocument(target?: Element | Window | Node | Document | null | undefined): Document;
|
|
6
|
-
export { getDocument }
|
|
7
|
-
export { getDocument as getDocument_alias_1 }
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Gets a reference to the root node of the document based on the given target.
|
|
11
|
-
*/
|
|
12
|
-
declare function getDocumentElement(target?: Element | Node | Window | Document | null | undefined): HTMLElement;
|
|
13
|
-
export { getDocumentElement }
|
|
14
|
-
export { getDocumentElement as getDocumentElement_alias_1 }
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Gets the window object for the given target or the global window object if no
|
|
18
|
-
* target is provided.
|
|
19
|
-
*/
|
|
20
|
-
declare function getWindow(target?: Node | ShadowRoot | Document | null | undefined): Window & typeof globalThis;
|
|
21
|
-
export { getWindow }
|
|
22
|
-
export { getWindow as getWindow_alias_1 }
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Checks if the given DOM node is a Document.
|
|
26
|
-
*/
|
|
27
|
-
declare function isDocument(node: Node): node is Document;
|
|
28
|
-
export { isDocument }
|
|
29
|
-
export { isDocument as isDocument_alias_1 }
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Checks if the given DOM node is a DocumentFragment.
|
|
33
|
-
*/
|
|
34
|
-
declare function isDocumentFragment(node: Node): node is DocumentFragment;
|
|
35
|
-
export { isDocumentFragment }
|
|
36
|
-
export { isDocumentFragment as isDocumentFragment_alias_1 }
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Checks if the given DOM node is an Element.
|
|
40
|
-
*/
|
|
41
|
-
declare function isElement(node: Node): node is Element;
|
|
42
|
-
export { isElement }
|
|
43
|
-
export { isElement as isElement_alias_1 }
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Checks if an unknown value is likely a DOM element.
|
|
47
|
-
*/
|
|
48
|
-
declare function isElementLike(value: unknown): value is Element;
|
|
49
|
-
export { isElementLike }
|
|
50
|
-
export { isElementLike as isElementLike_alias_1 }
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Checks if the given DOM node is an HTMLElement.
|
|
54
|
-
*/
|
|
55
|
-
declare function isHTMLElement(node: Node): node is HTMLElement;
|
|
56
|
-
export { isHTMLElement }
|
|
57
|
-
export { isHTMLElement as isHTMLElement_alias_1 }
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Checks if the given DOM node is an MathMLElement.
|
|
61
|
-
*/
|
|
62
|
-
declare function isMathMLElement(node: Node): node is MathMLElement;
|
|
63
|
-
export { isMathMLElement }
|
|
64
|
-
export { isMathMLElement as isMathMLElement_alias_1 }
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Checks if an unknown value is likely a DOM node.
|
|
68
|
-
*/
|
|
69
|
-
declare function isNodeLike(value: unknown): value is Node;
|
|
70
|
-
export { isNodeLike }
|
|
71
|
-
export { isNodeLike as isNodeLike_alias_1 }
|
|
72
|
-
|
|
73
|
-
declare function isObject(value: unknown): value is Record<string | symbol | number, unknown>;
|
|
74
|
-
export { isObject }
|
|
75
|
-
export { isObject as isObject_alias_1 }
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Checks if the given DOM node is a ShadowRoot.
|
|
79
|
-
*/
|
|
80
|
-
declare function isShadowRoot(node: Node): node is ShadowRoot;
|
|
81
|
-
export { isShadowRoot }
|
|
82
|
-
export { isShadowRoot as isShadowRoot_alias_1 }
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Checks if the given DOM node is an SVGElement.
|
|
86
|
-
*/
|
|
87
|
-
declare function isSVGElement(node: Node): node is SVGElement;
|
|
88
|
-
export { isSVGElement }
|
|
89
|
-
export { isSVGElement as isSVGElement_alias_1 }
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Checks if the given DOM node is a Text node.
|
|
93
|
-
*/
|
|
94
|
-
declare function isTextNode(node: Node): node is Text;
|
|
95
|
-
export { isTextNode }
|
|
96
|
-
export { isTextNode as isTextNode_alias_1 }
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Checks if the given value is likely a Window object.
|
|
100
|
-
*/
|
|
101
|
-
declare function isWindowLike(value: unknown): value is Window;
|
|
102
|
-
export { isWindowLike }
|
|
103
|
-
export { isWindowLike as isWindowLike_alias_1 }
|
|
104
|
-
|
|
105
|
-
export { }
|