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 🙏

© 2024 – Pkg Stats / Ryan Hefner

b64u

v3.0.0

Published

Tiny, lightweight module for encoding and decoding Base64 URLs

Downloads

26,880

Readme

⚡ b64u

Build Status npm npm license Powered by TypeScript

A tiny, lightweight module for encoding and decoding Base64 URLs (RFC 4648). Supports TypeScript, but also works without it.

NOTE: if you were previously using the unmaintained base64url package, this library is API-identical.

Requirements

  • NodeJS 8+

Installation

Install via yarn:

yarn add b64u

Or via NPM:

npm install --save b64u

Example

import b64u from 'b64u'

b64u('A tiny, lightweight module')
// 'QSB0aW55LCBsaWdodHdlaWdodCBtb2R1bGU'

b64u.encode('A tiny, lightweight module')
// 'QSB0aW55LCBsaWdodHdlaWdodCBtb2R1bGU'

b64u.decode('Zm9yIGVuY29kaW5nIGFuZCBkZWNvZGluZyBCYXNlNjQgVVJMcw')
// 'for encoding and decoding Base64 URLs'

b64u.toBase64('QSB0aW55LCBsaWdodHdlaWdodCBtb2R1bGU')
// 'QSB0aW55LCBsaWdodHdlaWdodCBtb2R1bGU='

b64u.fromBase64('QSB0aW55LCBsaWdodHdlaWdodCBtb2R1bGU=')
// 'QSB0aW55LCBsaWdodHdlaWdodCBtb2R1bGU'

b64u.toBuffer(b64u('tiny'))
// <Buffer 74 69 6e 79>

Usage

Either require or import the library:

const b64u = require('b64u')
import b64u from 'b64u'

API

b64u(input: string | Buffer, encoding = 'utf8'): string

b64u.encode(input: string | Buffer, encoding = 'utf8'): string

Encodes an input string or buffer into a Base64 URL. Optionally specify an encoding.

Example

b64u('A tiny, lightweight module')
// 'QSB0aW55LCBsaWdodHdlaWdodCBtb2R1bGU'

b64u.encode('A tiny, lightweight module')
// 'QSB0aW55LCBsaWdodHdlaWdodCBtb2R1bGU'

b64u.decode(input: string | Buffer, encoding = 'utf8'): string

Decodes an input Base64 URL into a raw string. Optionally specify an encoding.

Example

b64u.decode('Zm9yIGVuY29kaW5nIGFuZCBkZWNvZGluZyBCYXNlNjQgVVJMcw')
// 'for encoding and decoding Base64 URLs'

b64u.toBase64(input: string): string

Converts an input Base64 URL into a plain Base64 string.

Example

b64u.toBase64('QSB0aW55LCBsaWdodHdlaWdodCBtb2R1bGU')
// 'QSB0aW55LCBsaWdodHdlaWdodCBtb2R1bGU='

b64u.fromBase64(input: string): string

Converts an input plain Base64 string into a Base64 URL.

Example

b64u.fromBase64('QSB0aW55LCBsaWdodHdlaWdodCBtb2R1bGU=')
// 'QSB0aW55LCBsaWdodHdlaWdodCBtb2R1bGU'

b64u.toBuffer(input: string): Buffer

Converts an input Base64 URL into a Buffer with the raw bytes.

Example

b64u.toBuffer(b64u('tiny'))
// <Buffer 74 69 6e 79>

Background

This library began as an API-identical fork of the base64url package, as that package has not been updated since 2016 and currently suffers from a critical issue that prevents its use with TypeScript and any version of NodeJS other than Node 6.0.0.

Why the name, b64u? It's a tiny, lightweight name for a tiny, lightweight module!

License

The MIT license. See LICENSE.

Copyright (c) 2018 Jacob Gillespie

Copyright (c) 2013–2016 Brian J. Brennan