@yuhere/js-base64
v0.0.9
Published
Base64 encoding/decoding in pure JS
Readme
@yuhere/js-base64
Base64 encoding/decoding in pure JS, converted to TypeScript with ES module output.
Forked from github.com/beatgammit/base64-js.
Many browsers already have base64 encoding/decoding functionality, but it is for text data, not all-purpose binary data.
Sometimes encoding/decoding binary data in the browser is useful, and that is what this module does.
install
With npm do:
npm install @yuhere/js-base64usage
import { toByteArray, fromByteArray, byteLength } from '@yuhere/js-base64';methods
toByteArray(b64: string): Uint8Array— Decode a base64 string to a byte array. Supports both standard (+,/) and URL-safe (-,_) characters.fromByteArray(uint8: Uint8Array): string— Encode a byte array to a base64 string.byteLength(b64: string): number— Returns the number of bytes a base64 string encodes to. Useful for pre-allocating buffers.
build
npm run buildRuns vite build (JS + sourcemaps) then tsc (type declarations). Output in lib/.
test
npm testRuns Vitest tests (Node environment).
npm run test:watch # watch mode
npm run test:coverage # with Istanbul coverage reportbenchmark
npm run benchlicense
MIT
