@ocavue/utils 0.6.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/dist/index.d.ts CHANGED
@@ -62,6 +62,18 @@ declare function getDocument(target?: Element | Window | Node | Document | null)
62
62
  */
63
63
  declare function getDocumentElement(target?: Element | Node | Window | Document | null): HTMLElement;
64
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
+
65
77
  /**
66
78
  * Creates a function that will only execute the provided function once.
67
79
  * Subsequent calls will return the cached result from the first execution.
@@ -77,11 +89,4 @@ declare function getDocumentElement(target?: Element | Node | Window | Document
77
89
  */
78
90
  declare function once<T>(fn: () => T): () => T;
79
91
 
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 };
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
@@ -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;
@@ -80,23 +100,11 @@ function once(fn) {
80
100
  return result;
81
101
  };
82
102
  }
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
- }
96
103
  export {
97
104
  formatBytes,
98
105
  getDocument,
99
106
  getDocumentElement,
107
+ getId,
100
108
  getWindow,
101
109
  isDocument,
102
110
  isDocumentFragment,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ocavue/utils",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.7.1",
5
5
  "description": "",
6
6
  "author": "ocavue <ocavue@gmail.com>",
7
7
  "license": "MIT",