Skip to main content
Home

Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
Published4 months ago (0.2.11)

Fast constant time encoding and decoding for base16 / hex and base64 / base64url strings

Tiny Encodings

A companion library to join a few other tiny-* libraries.

This library provides reasonably fast implementations of:

  • Base64 Standard Encoding
  • Base64 URL Encoding
  • Base64 Standard Decoding
  • Base64 URL Decoding
  • Hex / Base16 Encoding
  • Hex / Base16 Decoding

Where decoding functions take strings and output a Uint8Arrays, and encoding functions take any buffer type (ArrayBuffer, Uint8Array, other typed arrays, and DataViews) and output a string.

This library follows the byte order of the host, this means that typed arrays such as Uint32Array will be encoded in the byte order in its underlying memory buffer which is host specific. If platform compatibility is required for multi-byte buffers, see arrayToEndian and arrayFromEndian.

Initially, this library was going to be the reference implementation, as seen in encoding_reference.ts. However, the reference implementation performance is abysmal.

This library is no longer automatically published to Deno's Third Party Modules. Newer versions may appear on deno.land/x, but do not work.

Tiny-encodings mitigates Base64 Malleability by refusing mangled encoded inputs.

Example

// NPM
// import { decodeBase64 } from "@levischuck/tiny-encodings";
// or JSR
// import { decodeBase64 } from "jsr:@levischuck/tiny-encodings";
import { decodeBase64 } from "./index.ts";

decodeBase64("SGVsbG8gd29ybGQ=");
// returns a Uint8Array with the bytes for "Hello world"

Where to get it

This library is available on NPM and JSR.

This library is no longer automatically published to Deno's Third Party Modules. Newer versions may appear on deno.land/x, but do not work.

Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@levischuck/tiny-encodings

Import symbol

import * as tiny_encodings from "@levischuck/tiny-encodings";
or

Import directly with a jsr specifier

import * as tiny_encodings from "jsr:@levischuck/tiny-encodings";

Add Package

pnpm i jsr:@levischuck/tiny-encodings
or (using pnpm 10.8 or older)
pnpm dlx jsr add @levischuck/tiny-encodings

Import symbol

import * as tiny_encodings from "@levischuck/tiny-encodings";

Add Package

yarn add jsr:@levischuck/tiny-encodings
or (using Yarn 4.8 or older)
yarn dlx jsr add @levischuck/tiny-encodings

Import symbol

import * as tiny_encodings from "@levischuck/tiny-encodings";

Add Package

vlt install jsr:@levischuck/tiny-encodings

Import symbol

import * as tiny_encodings from "@levischuck/tiny-encodings";

Add Package

npx jsr add @levischuck/tiny-encodings

Import symbol

import * as tiny_encodings from "@levischuck/tiny-encodings";

Add Package

bunx jsr add @levischuck/tiny-encodings

Import symbol

import * as tiny_encodings from "@levischuck/tiny-encodings";