@fuzdev/fuz_util 0.53.1 → 0.53.2

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/bytes.d.ts CHANGED
@@ -11,4 +11,11 @@
11
11
  * @returns `Uint8Array` view of the data.
12
12
  */
13
13
  export declare const to_bytes: (data: BufferSource | string) => Uint8Array;
14
+ /**
15
+ * Formats a byte count as a human-readable string.
16
+ *
17
+ * @param n - byte count.
18
+ * @returns formatted string like `'1.2 KB'` or `'3.4 MB'`.
19
+ */
20
+ export declare const format_bytes: (n: number) => string;
14
21
  //# sourceMappingURL=bytes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/bytes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM,YAAY,GAAG,MAAM,KAAG,UAKtD,CAAC"}
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/bytes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM,YAAY,GAAG,MAAM,KAAG,UAKtD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,GAAG,MAAM,KAAG,MAKxC,CAAC"}
package/dist/bytes.js CHANGED
@@ -20,3 +20,18 @@ export const to_bytes = (data) => {
20
20
  return new Uint8Array(data);
21
21
  return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
22
22
  };
23
+ /**
24
+ * Formats a byte count as a human-readable string.
25
+ *
26
+ * @param n - byte count.
27
+ * @returns formatted string like `'1.2 KB'` or `'3.4 MB'`.
28
+ */
29
+ export const format_bytes = (n) => {
30
+ if (n < 1024)
31
+ return n + ' B';
32
+ if (n < 1024 * 1024)
33
+ return (n / 1024).toFixed(1) + ' KB';
34
+ if (n < 1024 * 1024 * 1024)
35
+ return (n / (1024 * 1024)).toFixed(1) + ' MB';
36
+ return (n / (1024 * 1024 * 1024)).toFixed(1) + ' GB';
37
+ };
@@ -2,9 +2,17 @@
2
2
  * BLAKE3 cryptographic hashing via `@fuzdev/blake3_wasm`.
3
3
  *
4
4
  * Synchronous and fast. Returns hex-encoded 256-bit (32-byte) digests.
5
+ * WASM initialization starts eagerly on import. Await `blake3_ready` before first use
6
+ * in browser contexts where the WASM must be fetched asynchronously.
5
7
  *
6
8
  * @module
7
9
  */
10
+ /**
11
+ * Resolves when the BLAKE3 WASM module is initialized and ready.
12
+ * Initialization starts eagerly on import. Idempotent — safe to await multiple times.
13
+ * In Node.js/Deno (sync init), this resolves immediately.
14
+ */
15
+ export declare const blake3_ready: Promise<void>;
8
16
  /**
9
17
  * Computes a BLAKE3 hash synchronously.
10
18
  *
@@ -1 +1 @@
1
- {"version":3,"file":"hash_blake3.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/hash_blake3.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,YAAY,GAAG,MAAM,KAAG,MAAsC,CAAC"}
1
+ {"version":3,"file":"hash_blake3.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/hash_blake3.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAOH;;;;GAIG;AACH,eAAO,MAAM,YAAY,eAAS,CAAC;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,YAAY,GAAG,MAAM,KAAG,MAAsC,CAAC"}
@@ -2,12 +2,20 @@
2
2
  * BLAKE3 cryptographic hashing via `@fuzdev/blake3_wasm`.
3
3
  *
4
4
  * Synchronous and fast. Returns hex-encoded 256-bit (32-byte) digests.
5
+ * WASM initialization starts eagerly on import. Await `blake3_ready` before first use
6
+ * in browser contexts where the WASM must be fetched asynchronously.
5
7
  *
6
8
  * @module
7
9
  */
8
- import { hash } from '@fuzdev/blake3_wasm';
10
+ import { hash, init } from '@fuzdev/blake3_wasm';
9
11
  import { to_hex } from './hex.js';
10
12
  import { to_bytes } from './bytes.js';
13
+ /**
14
+ * Resolves when the BLAKE3 WASM module is initialized and ready.
15
+ * Initialization starts eagerly on import. Idempotent — safe to await multiple times.
16
+ * In Node.js/Deno (sync init), this resolves immediately.
17
+ */
18
+ export const blake3_ready = init();
11
19
  /**
12
20
  * Computes a BLAKE3 hash synchronously.
13
21
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fuzdev/fuz_util",
3
- "version": "0.53.1",
3
+ "version": "0.53.2",
4
4
  "description": "utility belt for JS",
5
5
  "glyph": "🦕",
6
6
  "logo": "logo.svg",
package/src/lib/bytes.ts CHANGED
@@ -19,3 +19,16 @@ export const to_bytes = (data: BufferSource | string): Uint8Array => {
19
19
  if (data instanceof ArrayBuffer) return new Uint8Array(data);
20
20
  return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
21
21
  };
22
+
23
+ /**
24
+ * Formats a byte count as a human-readable string.
25
+ *
26
+ * @param n - byte count.
27
+ * @returns formatted string like `'1.2 KB'` or `'3.4 MB'`.
28
+ */
29
+ export const format_bytes = (n: number): string => {
30
+ if (n < 1024) return n + ' B';
31
+ if (n < 1024 * 1024) return (n / 1024).toFixed(1) + ' KB';
32
+ if (n < 1024 * 1024 * 1024) return (n / (1024 * 1024)).toFixed(1) + ' MB';
33
+ return (n / (1024 * 1024 * 1024)).toFixed(1) + ' GB';
34
+ };
@@ -2,15 +2,24 @@
2
2
  * BLAKE3 cryptographic hashing via `@fuzdev/blake3_wasm`.
3
3
  *
4
4
  * Synchronous and fast. Returns hex-encoded 256-bit (32-byte) digests.
5
+ * WASM initialization starts eagerly on import. Await `blake3_ready` before first use
6
+ * in browser contexts where the WASM must be fetched asynchronously.
5
7
  *
6
8
  * @module
7
9
  */
8
10
 
9
- import {hash} from '@fuzdev/blake3_wasm';
11
+ import {hash, init} from '@fuzdev/blake3_wasm';
10
12
 
11
13
  import {to_hex} from './hex.js';
12
14
  import {to_bytes} from './bytes.js';
13
15
 
16
+ /**
17
+ * Resolves when the BLAKE3 WASM module is initialized and ready.
18
+ * Initialization starts eagerly on import. Idempotent — safe to await multiple times.
19
+ * In Node.js/Deno (sync init), this resolves immediately.
20
+ */
21
+ export const blake3_ready = init();
22
+
14
23
  /**
15
24
  * Computes a BLAKE3 hash synchronously.
16
25
  *