ts-bos-base64
v1.0.0
Published
Pure-TypeScript port of BabyOS algo_base64.c — RFC 4648 Base64 encoder/decoder.
Downloads
125
Maintainers
Readme
ts-bos-base64
A pure-TypeScript port of BabyOS's
algo_base64.c — a compact RFC 4648 Base64 encoder/decoder.
- No native dependencies. Browser- and Node-compatible.
- Tested against the RFC 4648 §10 reference vectors and a 0..255 binary round-trip.
Install
npm install @scott/bos-base64Usage
import { encode, decode, decodeToString } from '@scott/bos-base64';
encode('Hello, world!'); // 'SGVsbG8sIHdvcmxkIQ=='
decodeToString('SGVsbG8sIHdvcmxkIQ=='); // 'Hello, world!'
const bytes = decode('AAECAwQFBgc='); // Uint8Array of decoded bytesdecode returns null if the input is malformed (length not a multiple of
4, or any illegal character).
API
encode(input: Uint8Array | string): stringdecode(input: string): Uint8Array | nulldecodeToString(input: string): string | null
Upstream
Originally from notrynohigh/BabyOS (MIT, copyright 2020 Bean).
License
MIT — see LICENSE.
