npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

base85n

v0.5.1

Published

Base85N: a compact encoding for data embedded in text formats (JSON, XML, HTML, config), with Dynamic Passthrough and Fill modes

Readme

base85n

A TypeScript implementation of Base85N, an encoding for data that has to be embedded in a text-based format — JSON, XML, HTML attributes, configuration files — where Base64 would otherwise be used and the size or the cleanliness of the result matters. It uses a single 85-character alphabet (Alphabet-N) that excludes ", ', \, <, >, & and all whitespace, so output goes into a JSON string, an XML node or a quoted attribute with no second escaping layer, with an adaptive Dynamic Passthrough (DP) mode for efficient, partially human-readable representation of compatible byte sequences. See the specification for the full normative text, in particular Section 4.2's eight replacement alphabets and Section 6.1's single-scan Dynamic Passthrough encoding procedure, which this package follows exactly.

Before you embed the output: four containers need the value quoted. Alphabet-N does contain `, $, { and = — free in JSON, XML and HTML, not free everywhere. So encoded output must not be pasted raw into a JavaScript template literal (` ends it, ${ interpolates — both occur in ordinary output, a backtick about one character in 85), an unquoted HTML attribute, a plain YAML scalar, or a double-quoted shell word. An ordinary '…' or "…" string is always safe. Full table, checked against real parsers: Embedding: where the output can be pasted verbatim.

Install

npm install base85n

Or, to work on this package inside a clone of the repository, npm install with no arguments from this directory.

Build

npm run build

Compiles src/ to dist/ (ESM, with .d.ts type declarations) using tsc.

Test

npm test

Runs the vitest suite under test/, which:

  • Verifies every golden vector in ../testvectors/vectors.json round-trips through both encode and decode.
  • Runs seeded (deterministic) random round-trip property tests across a wide range of input lengths and byte compositions (raw random bytes, Alphabet-N literals, R-Set characters, and donor characters).
  • Exercises explicit edge cases: empty input, 1-4 byte inputs, the MIN_PASSTHROUGH_BYTES boundary, multi-segment DP output (> MAX_DP_OUTPUT_CHARS_PER_SIGNAL characters), the MAX_DP_ANALYSIS_BYTES window boundary, and every byte value 0-255.
  • Asserts decode() throws a Base85NDecodeError (never returns garbage) on a variety of malformed inputs.

Usage

import { encode, decode, Base85NDecodeError } from "base85n";

const bytes = new Uint8Array([72, 101, 108, 108, 111]);
const text = encode(bytes); // => Base85N-encoded string

try {
  const roundTripped = decode(text); // => Uint8Array, equal to `bytes`
} catch (err) {
  if (err instanceof Base85NDecodeError) {
    console.error(err.code, err.message);
  }
}

API

function encode(data: Uint8Array): string;
function decode(s: string): Uint8Array; // throws Base85NDecodeError

class Base85NDecodeError extends Error {
  readonly code:
    | "invalid_character"
    | "unexpected_end_of_stream"
    | "undefined_signal"
    | "invalid_final_block";
  readonly position: number | undefined; // index into the whitespace-stripped input, if known
}

Also exported: the ALPHABET_N_CHARS_STR, MIN_PASSTHROUGH_BYTES, MAX_DP_OUTPUT_CHARS_PER_SIGNAL, MAX_DP_ANALYSIS_BYTES and REPLACEMENT_ALPHABETS from the specification.

Versioning

The major and minor version track the specification version this package implements — 0.5.x implements specification v0.5.0, whose wire format is frozen. The patch level is this package's own: packaging and documentation fixes that change no encoded output. Anything that would change the wire format would change the specification's version first.