You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+63-37Lines changed: 63 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
6
6
# bytecodec
7
7
8
-
Typed JavaScript and TypeScript byte utilities for base64, base64url, hex, Z85, UTF-8 strings, unsigned BigInt conversion, JSON, gzip, concatenation, comparison, and byte-source normalization. The package ships tree-shakeable ESM plus CommonJS entry points and keeps the same API across Node, Bun, Deno, browsers, and edge runtimes.
8
+
Typed JavaScript and TypeScript byte utilities for base58, base58btc, base64, base64url, hex, Z85, UTF-8 strings, unsigned BigInt conversion, JSON, gzip, concatenation, comparison, and byte-source normalization. The package ships tree-shakeable ESM plus CommonJS entry points and keeps the same API across Node, Bun, Deno, browsers, and edge runtimes.
9
9
10
10
## Compatibility
11
11
@@ -17,7 +17,7 @@ Typed JavaScript and TypeScript byte utilities for base64, base64url, hex, Z85,
17
17
18
18
## Goals
19
19
20
-
- Developer-friendly API for base64, base64url, hex, Z85, UTF-8, unsigned BigInt conversion, JSON, gzip, concat, equality, and byte normalization.
20
+
- Developer-friendly API for base58, base58btc, base64, base64url, hex, Z85, UTF-8, unsigned BigInt conversion, JSON, gzip, concat, equality, and byte normalization.
21
21
- No runtime dependencies or bundler shims.
22
22
- Tree-shakeable ESM by default with CommonJS compatibility and no side effects.
23
23
- Returns copies for safety when normalizing inputs.
`base58btc` uses the Bitcoin base58 alphabet and adds the multibase `z` prefix.
84
+
63
85
### CommonJS
64
86
65
87
```js
@@ -184,7 +206,7 @@ const joined = concat([new Uint8Array([1, 2]), new Uint8Array([3, 4]), [5, 6]])
184
206
185
207
### Node
186
208
187
-
Uses `Buffer.from` for base64 helpers, `TextEncoder` and `TextDecoder` when available with `Buffer` fallback for UTF-8, and `node:zlib` for gzip.
209
+
Uses pure JavaScript for base58/base58btc, `Buffer.from` for base64 helpers, `TextEncoder` and `TextDecoder` when available with `Buffer` fallback for UTF-8, and `node:zlib` for gzip.
Validation failures throw `BytecodecError` instances with a `code` string, for example `BASE64URL_INVALID_LENGTH`, `BIGINT_UNSIGNED_EXPECTED`, `HEX_INVALID_CHARACTER`, `Z85_INVALID_BLOCK`, `BASE64_DECODER_UNAVAILABLE`, `UTF8_DECODER_UNAVAILABLE`, and `GZIP_COMPRESSION_UNAVAILABLE`. Messages are prefixed with `{@sovereignbase/bytecodec}`.
221
+
Validation failures throw `BytecodecError` instances with a `code` string, for example `BASE58_INVALID_CHARACTER`, `BASE58BTC_INVALID_PREFIX`, `BASE64URL_INVALID_LENGTH`, `BIGINT_UNSIGNED_EXPECTED`, `HEX_INVALID_CHARACTER`, `Z85_INVALID_BLOCK`, `BASE64_DECODER_UNAVAILABLE`, `UTF8_DECODER_UNAVAILABLE`, and `GZIP_COMPRESSION_UNAVAILABLE`. Messages are prefixed with `{@sovereignbase/bytecodec}`.
200
222
201
223
### Safety / copying semantics
202
224
@@ -206,44 +228,48 @@ Validation failures throw `BytecodecError` instances with a `code` string, for e
206
228
207
229
`npm test` covers:
208
230
209
-
-75 unit tests
210
-
-7 integration tests
211
-
- Node E2E: 23/23 passed in ESM and 23/23 passed in CommonJS
212
-
- Bun E2E: 23/23 passed in ESM and 23/23 passed in CommonJS
213
-
- Deno E2E: 23/23 passed in ESM
214
-
- Cloudflare Workers E2E: 23/23 passed in ESM
215
-
- Edge Runtime E2E: 23/23 passed in ESM
231
+
-85 unit tests
232
+
-9 integration tests
233
+
- Node E2E: 27/27 passed in ESM and 27/27 passed in CommonJS
234
+
- Bun E2E: 27/27 passed in ESM and 27/27 passed in CommonJS
235
+
- Deno E2E: 27/27 passed in ESM
236
+
- Cloudflare Workers E2E: 27/27 passed in ESM
237
+
- Edge Runtime E2E: 27/27 passed in ESM
216
238
- Browser E2E: 5/5 passed in Chromium, Firefox, WebKit, mobile-chrome, and mobile-safari
217
239
- Coverage gate: 100% statements, branches, functions, and lines
218
240
219
241
## Benchmarks
220
242
221
-
Latest local `npm run bench` run on 2026-03-27 with Node `v22.14.0 (win32 x64)`:
222
-
223
-
| Benchmark | Result |
224
-
| ---------------- | ------------------------- |
225
-
| base64 encode | 979,522 ops/s (51.0 ms) |
226
-
| base64 decode | 1,825,737 ops/s (27.4 ms) |
227
-
| base64url encode | 407,973 ops/s (122.6 ms) |
228
-
| base64url decode | 560,991 ops/s (89.1 ms) |
229
-
| hex encode | 781,944 ops/s (63.9 ms) |
230
-
| hex decode | 806,002 ops/s (62.0 ms) |
231
-
| z85 encode | 170,125 ops/s (293.9 ms) |
232
-
| z85 decode | 1,141,472 ops/s (43.8 ms) |
233
-
| utf8 encode | 1,241,977 ops/s (40.3 ms) |
234
-
| utf8 decode | 2,610,407 ops/s (19.2 ms) |
235
-
| bigint encode | 490,692 ops/s (101.9 ms) |
236
-
| bigint decode | 428,938 ops/s (116.6 ms) |
237
-
| json encode | 588,066 ops/s (34.0 ms) |
238
-
| json decode | 603,058 ops/s (33.2 ms) |
239
-
| concat 3 buffers | 560,639 ops/s (89.2 ms) |
240
-
| toUint8Array | 6,292,910 ops/s (31.8 ms) |
241
-
| toArrayBuffer | 677,822 ops/s (295.1 ms) |
242
-
| toBufferSource | 7,465,472 ops/s (26.8 ms) |
243
-
| equals same | 2,217,064 ops/s (90.2 ms) |
244
-
| equals diff | 2,302,002 ops/s (86.9 ms) |
245
-
| gzip compress | 3,473 ops/s (115.2 ms) |
246
-
| gzip decompress | 4,753 ops/s (84.2 ms) |
243
+
Latest local `npm run bench` run on 2026-04-17 with Node `v22.14.0 (win32 x64)`. Each benchmark uses the same `5,000` operations:
0 commit comments