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

@phantom/base64url

v1.0.2

Published

Isomorphic base64url encoding/decoding utilities

Readme

@phantom/base64url

Isomorphic base64url encoding/decoding utilities that work in both browser and Node.js environments.

Installation

npm install @phantom/base64url

Features

  • 🌐 Isomorphic - Works in both browser and Node.js
  • 🚀 Zero dependencies - Lightweight and fast
  • 📱 Modern & Legacy - Supports both modern APIs and older browsers
  • 🔒 URL-safe - Uses base64url format (RFC 4648)
  • 📦 TypeScript - Full type support included

Usage

import { base64urlEncode, base64urlDecode, stringToBase64url, base64urlDecodeToString } from "@phantom/base64url";

// Encode string to base64url
const encoded = stringToBase64url("Hello World");
console.log(encoded); // "SGVsbG8gV29ybGQ"

// Decode base64url to string
const decoded = base64urlDecodeToString(encoded);
console.log(decoded); // "Hello World"

// Encode Uint8Array to base64url
const bytes = new Uint8Array([72, 101, 108, 108, 111]);
const encodedBytes = base64urlEncode(bytes);
console.log(encodedBytes); // "SGVsbG8"

// Decode base64url to Uint8Array
const decodedBytes = base64urlDecode(encodedBytes);
console.log(decodedBytes); // Uint8Array([72, 101, 108, 108, 111])

API Reference

base64urlEncode(data: string | Uint8Array | ArrayLike<number>): string

Encodes data to base64url format.

  • data: String, Uint8Array, or ArrayLike data to encode
  • Returns: base64url encoded string (no padding, URL-safe)

base64urlDecode(str: string): Uint8Array

Decodes base64url string to Uint8Array.

  • str: base64url encoded string
  • Returns: decoded Uint8Array

stringToBase64url(str: string): string

Encodes UTF-8 string to base64url format.

  • str: UTF-8 string to encode
  • Returns: base64url encoded string

base64urlDecodeToString(str: string): string

Decodes base64url string to UTF-8 string.

  • str: base64url encoded string
  • Returns: decoded UTF-8 string

Base64url Format

Base64url is a URL-safe variant of Base64 encoding defined in RFC 4648:

  • Uses - instead of +
  • Uses _ instead of /
  • Removes padding (=) characters
  • Safe to use in URLs, filenames, and HTTP headers

Browser Compatibility

  • Modern browsers: Uses native btoa/atob and TextEncoder/TextDecoder
  • Legacy browsers: Provides fallbacks for older environments
  • Node.js: Uses Buffer for optimal performance

Examples

JWT Token Handling

import { stringToBase64url, base64urlDecodeToString } from "@phantom/base64url";

const payload = JSON.stringify({
  sub: "1234567890",
  name: "John Doe",
  iat: 1516239022,
});

const encodedPayload = stringToBase64url(payload);
console.log(`JWT payload: ${encodedPayload}`);

const decodedPayload = base64urlDecodeToString(encodedPayload);
console.log(JSON.parse(decodedPayload));

Binary Data Encoding

import { base64urlEncode, base64urlDecode } from "@phantom/base64url";

// Encode binary data
const binaryData = new Uint8Array([0xff, 0xfe, 0xfd, 0xfc]);
const encoded = base64urlEncode(binaryData);
console.log(encoded); // URL-safe encoded string

// Decode back to binary
const decoded = base64urlDecode(encoded);
console.log(decoded); // Original Uint8Array

API Integration

import { stringToBase64url } from "@phantom/base64url";

// Safe for URL parameters
const userData = JSON.stringify({ userId: 123, action: "login" });
const safeParam = stringToBase64url(userData);

// Use in URL without encoding issues
const apiUrl = `https://api.example.com/auth?data=${safeParam}`;

License

MIT