@ocavue/utils 0.5.0 → 0.7.1
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/README.md +4 -0
- package/dist/index.d.ts +16 -1
- package/dist/index.js +23 -1
- package/package.json +8 -8
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the given value is an object.
|
|
3
|
+
*/
|
|
1
4
|
declare function isObject(value: unknown): value is Record<string | symbol | number, unknown>;
|
|
2
5
|
|
|
3
6
|
/**
|
|
@@ -59,6 +62,18 @@ declare function getDocument(target?: Element | Window | Node | Document | null)
|
|
|
59
62
|
*/
|
|
60
63
|
declare function getDocumentElement(target?: Element | Node | Window | Document | null): HTMLElement;
|
|
61
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Formats a number of bytes into a human-readable string.
|
|
67
|
+
* @param bytes - The number of bytes to format.
|
|
68
|
+
* @returns A string representing the number of bytes in a human-readable format.
|
|
69
|
+
*/
|
|
70
|
+
declare function formatBytes(bytes: number): string;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Generates a unique positive integer.
|
|
74
|
+
*/
|
|
75
|
+
declare function getId(): number;
|
|
76
|
+
|
|
62
77
|
/**
|
|
63
78
|
* Creates a function that will only execute the provided function once.
|
|
64
79
|
* Subsequent calls will return the cached result from the first execution.
|
|
@@ -74,4 +89,4 @@ declare function getDocumentElement(target?: Element | Node | Window | Document
|
|
|
74
89
|
*/
|
|
75
90
|
declare function once<T>(fn: () => T): () => T;
|
|
76
91
|
|
|
77
|
-
export { getDocument, getDocumentElement, getWindow, isDocument, isDocumentFragment, isElement, isElementLike, isHTMLElement, isMathMLElement, isNodeLike, isObject, isSVGElement, isShadowRoot, isTextNode, isWindowLike, once };
|
|
92
|
+
export { formatBytes, getDocument, getDocumentElement, getId, getWindow, isDocument, isDocumentFragment, isElement, isElementLike, isHTMLElement, isMathMLElement, isNodeLike, isObject, isSVGElement, isShadowRoot, isTextNode, isWindowLike, once };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/checker.ts
|
|
2
2
|
function isObject(value) {
|
|
3
|
-
return value != null && typeof value === "object"
|
|
3
|
+
return value != null && typeof value === "object";
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
// src/dom.ts
|
|
@@ -67,6 +67,26 @@ function getDocumentElement(target) {
|
|
|
67
67
|
return getDocument(target).documentElement;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// src/format-bytes.ts
|
|
71
|
+
function formatBytes(bytes) {
|
|
72
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
73
|
+
let unitIndex = 0;
|
|
74
|
+
let num = bytes;
|
|
75
|
+
while (Math.abs(num) >= 1024 && unitIndex < units.length - 1) {
|
|
76
|
+
num /= 1024;
|
|
77
|
+
unitIndex++;
|
|
78
|
+
}
|
|
79
|
+
const fraction = unitIndex === 0 && num % 1 === 0 ? 0 : 1;
|
|
80
|
+
return `${num.toFixed(fraction)}${units[unitIndex]}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/get-id.ts
|
|
84
|
+
var id = 0;
|
|
85
|
+
function getId() {
|
|
86
|
+
id = id % Number.MAX_SAFE_INTEGER + 1;
|
|
87
|
+
return id;
|
|
88
|
+
}
|
|
89
|
+
|
|
70
90
|
// src/once.ts
|
|
71
91
|
function once(fn) {
|
|
72
92
|
let called = false;
|
|
@@ -81,8 +101,10 @@ function once(fn) {
|
|
|
81
101
|
};
|
|
82
102
|
}
|
|
83
103
|
export {
|
|
104
|
+
formatBytes,
|
|
84
105
|
getDocument,
|
|
85
106
|
getDocumentElement,
|
|
107
|
+
getId,
|
|
86
108
|
getWindow,
|
|
87
109
|
isDocument,
|
|
88
110
|
isDocumentFragment,
|
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.7.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "ocavue <ocavue@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,18 +36,18 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@ocavue/eslint-config": "^3.
|
|
39
|
+
"@ocavue/eslint-config": "^3.2.0",
|
|
40
40
|
"@ocavue/tsconfig": "^0.3.7",
|
|
41
41
|
"@size-limit/preset-small-lib": "^11.2.0",
|
|
42
42
|
"@types/node": "^20.17.27",
|
|
43
|
-
"eslint": "^9.
|
|
44
|
-
"jsdom": "^26.
|
|
45
|
-
"prettier": "^3.
|
|
43
|
+
"eslint": "^9.31.0",
|
|
44
|
+
"jsdom": "^26.1.0",
|
|
45
|
+
"prettier": "^3.6.2",
|
|
46
46
|
"size-limit": "^11.2.0",
|
|
47
47
|
"tsup": "^8.5.0",
|
|
48
|
-
"typescript": "^5.
|
|
49
|
-
"vite": "^6.
|
|
50
|
-
"vitest": "^3.
|
|
48
|
+
"typescript": "^5.8.3",
|
|
49
|
+
"vite": "^6.3.5",
|
|
50
|
+
"vitest": "^3.2.4"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|