@ocavue/utils 0.5.0 → 0.6.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/README.md +4 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.js +15 -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
|
/**
|
|
@@ -74,4 +77,11 @@ declare function getDocumentElement(target?: Element | Node | Window | Document
|
|
|
74
77
|
*/
|
|
75
78
|
declare function once<T>(fn: () => T): () => T;
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Formats a number of bytes into a human-readable string.
|
|
82
|
+
* @param bytes - The number of bytes to format.
|
|
83
|
+
* @returns A string representing the number of bytes in a human-readable format.
|
|
84
|
+
*/
|
|
85
|
+
declare function formatBytes(bytes: number): string;
|
|
86
|
+
|
|
87
|
+
export { formatBytes, getDocument, getDocumentElement, 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
|
|
@@ -80,7 +80,21 @@ function once(fn) {
|
|
|
80
80
|
return result;
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
+
|
|
84
|
+
// src/format-bytes.ts
|
|
85
|
+
function formatBytes(bytes) {
|
|
86
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
87
|
+
let unitIndex = 0;
|
|
88
|
+
let num = bytes;
|
|
89
|
+
while (Math.abs(num) >= 1024 && unitIndex < units.length - 1) {
|
|
90
|
+
num /= 1024;
|
|
91
|
+
unitIndex++;
|
|
92
|
+
}
|
|
93
|
+
const fraction = unitIndex === 0 && num % 1 === 0 ? 0 : 1;
|
|
94
|
+
return `${num.toFixed(fraction)}${units[unitIndex]}`;
|
|
95
|
+
}
|
|
83
96
|
export {
|
|
97
|
+
formatBytes,
|
|
84
98
|
getDocument,
|
|
85
99
|
getDocumentElement,
|
|
86
100
|
getWindow,
|
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.6.0",
|
|
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"
|