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

@chaisser/base64-url

v1.0.0

Published

URL-safe base64 encoding and decoding

Readme

🔐 @chaisser/base64-url

URL-safe base64 encoding and decoding — encode, decode, validate, JSON, hex, buffers


✨ Features

  • 🎯 Type-safe - Full TypeScript support
  • 🔗 URL-safe - No +, /, or = characters in output
  • 📦 Buffer support - Encode/decode Uint8Array and Buffer
  • Validation - Check and validate base64url strings
  • 📋 JSON helpers - Encode/decode JSON objects directly
  • 🔧 Hex helpers - Encode/decode hex strings
  • 🔄 Escape/unescape - Convert between standard and URL-safe base64
  • 🪶 Zero dependencies - Lightweight and tree-shakeable
  • 🏎️ ESM + CJS - Dual module format support

📦 Installation

npm install @chaisser/base64-url
# or
yarn add @chaisser/base64-url
# or
pnpm add @chaisser/base64-url

🚀 Quick Start

import { encode, decode, encodeJSON, decodeJSON } from '@chaisser/base64-url';

// Encode/decode strings
encode('hello world');   // 'aGVsbG8gd29ybGQ'
decode('aGVsbG8gd29ybGQ'); // 'hello world'

// JSON round-trip
const token = encodeJSON({ userId: 42, role: 'admin' });
// 'eyJ1c2VySWQiOjQyLCJyb2xlIjoiYWRtaW4ifQ'
const data = decodeJSON(token);
// { userId: 42, role: 'admin' }

📖 What It Does

This package provides URL-safe base64 encoding and decoding utilities for JavaScript and TypeScript. It replaces + with -, / with _, and strips trailing = padding per RFC 4648 §5. Supports strings, buffers, hex, JSON, and validation.


💡 Usage Examples

String Encode / Decode

import { encode, decode } from '@chaisser/base64-url';

encode('hello');         // 'aGVsbG8'
decode('aGVsbG8');       // 'hello'

// Unicode
encode('héllo wörld 🌍'); // URL-safe output

Buffer / Uint8Array

import { encodeBuffer, decodeToBuffer, decodeToUint8Array } from '@chaisser/base64-url';

const bytes = new Uint8Array([104, 101, 108, 108, 111]);
encodeBuffer(bytes);          // 'aGVsbG8'

const buf = decodeToBuffer('aGVsbG8');
buf.toString('utf-8');        // 'hello'

const arr = decodeToUint8Array('aGVsbG8');
// Uint8Array [104, 101, 108, 108, 111]

Escape / Unescape (convert formats)

import { escape, unescape } from '@chaisser/base64-url';

// Standard base64 → URL-safe
escape('a+b/c==');  // 'a-b_c'

// URL-safe → Standard base64 (with padding)
unescape('a-b_c');  // 'a+b/c=='

Validation

import { isBase64Url, validate } from '@chaisser/base64-url';

isBase64Url('aGVsbG8');   // true
isBase64Url('a+b/c=');    // false

validate('aGVsbG8');      // ok
validate('a+b/c=');       // throws Error

JSON Helpers

import { encodeJSON, decodeJSON } from '@chaisser/base64-url';

const token = encodeJSON({ sub: 'user123', exp: 1700000000 });
const payload = decodeJSON<{ sub: string; exp: number }>(token);

Hex Helpers

import { encodeHex, decodeHex } from '@chaisser/base64-url';

encodeHex('68656c6c6f');  // 'aGVsbG8'
decodeHex('aGVsbG8');     // '68656c6c6f'

📚 API Reference

String Encoding

| Function | Signature | Description | |---|---|---| | encode(input) | (string) → string | Encode UTF-8 string to base64url | | decode(input) | (string) → string | Decode base64url to UTF-8 string |

Buffer Encoding

| Function | Signature | Description | |---|---|---| | encodeBuffer(input) | (Uint8Array \| Buffer) → string | Encode bytes to base64url | | decodeToBuffer(input) | (string) → Buffer | Decode to Buffer | | decodeToUint8Array(input) | (string) → Uint8Array | Decode to Uint8Array |

Format Conversion

| Function | Signature | Description | |---|---|---| | escape(input) | (string) → string | Standard base64 → URL-safe | | unescape(input) | (string) → string | URL-safe → standard base64 |

Validation

| Function | Signature | Description | |---|---|---| | isBase64Url(input) | (string) → boolean | Check if string is valid base64url | | validate(input) | (string) → void | Throw if not valid base64url |

JSON

| Function | Signature | Description | |---|---|---| | encodeJSON(obj) | (unknown) → string | JSON.stringify → base64url | | decodeJSON(input) | (string) → T | base64url → JSON.parse |

Hex

| Function | Signature | Description | |---|---|---| | encodeHex(hex) | (string) → string | Hex string → base64url | | decodeHex(input) | (string) → string | base64url → hex string |


🔗 Related Packages

Explore our other utility packages in the @chaisser namespace:


🔒 License

MIT - Free to use in personal and commercial projects


👨 Developed by

Doruk Karaboncuk [email protected]


📄 Repository


🤝 Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest new features
  • Submit pull requests
  • Improve documentation

📞 Support

For issues, questions, or suggestions, please reach out through:


Made with ❤️ by @chaisser