codeckit
v0.1.1
Published
Tiny, isomorphic Base64 / Base64URL / hex codec — string and Uint8Array, Node and browser, no Buffer. Zero dependencies.
Maintainers
Readme
codeckit
Tiny, isomorphic Base64 / Base64URL / hex codec — strings and
Uint8Array, Node and browser, noBuffer. Zero dependencies.
Buffer doesn't exist in the browser, and btoa/atob choke on Unicode and
binary data. codeckit does Base64, Base64URL, and hex the same way everywhere —
between strings and Uint8Array — with byte-for-byte output matching Node's
Buffer. Zero dependencies, tree-shakeable.
import { base64Encode, base64Decode } from "codeckit";
base64Encode("héllo 😀"); // "aMOpbGxvIPCfmIA=" (UTF-8 safe)
base64Decode("aMOpbGxvIPCfmIA="); // "héllo 😀"Why codeckit?
- Isomorphic. Identical results in Node, Deno, Bun, and browsers — no
Buffer, nobtoa. - Unicode-safe. Strings are encoded as UTF-8, so emoji and accents survive
(
btoa("😀")throws — this doesn't). - Base64URL built in.
{ url: true }for-/_,{ pad: false }to drop=— exactly what JWTs and URLs want. - Bytes or text. Low-level
Uint8Array↔ string functions, plus text convenience wrappers. - Correct & verified. Output matches Node's
Bufferbyte-for-byte across the test suite. - Zero dependencies, ESM + CJS + types, tree-shakeable.
Install
npm install codeckit
# or: pnpm add codeckit / yarn add codeckit / bun add codeckitText helpers
import { base64Encode, base64Decode, hexEncode, hexDecode } from "codeckit";
base64Encode("hello"); // "aGVsbG8="
base64Encode("data", { url: true, pad: false }); // URL-safe, unpadded
base64Decode("aGVsbG8="); // "hello"
hexEncode("hi"); // "6869"
hexDecode("6869"); // "hi"Bytes
import {
bytesToBase64, base64ToBytes,
bytesToHex, hexToBytes,
utf8Encode, utf8Decode,
} from "codeckit";
bytesToBase64(new Uint8Array([1, 2, 3])); // "AQID"
base64ToBytes("AQID"); // Uint8Array [1, 2, 3]
bytesToHex(new Uint8Array([255, 16, 0])); // "ff1000"
hexToBytes("0xDEAD"); // Uint8Array [222, 173]
utf8Encode("héllo"); // Uint8Array (UTF-8)
utf8Decode(bytes); // stringbase64ToBytes accepts standard or URL-safe input, padded or not, and skips
whitespace. hexToBytes is case-insensitive and tolerates a 0x prefix and
spaces.
interface Base64Options {
url?: boolean; // -/_ alphabet (default false)
pad?: boolean; // emit = padding (default true)
}Contributors ✨
This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
License
MIT © Tung Tran
