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

@i-xi-dev/base64

v4.1.13

Published

A JavaScript Base64 encoder and decoder, implements Forgiving base64 defined in WHATWG Infra Standard.

Downloads

387

Readme

@i-xi-dev/base64

A JavaScript Base64 encoder and decoder, implements Forgiving base64 defined in WHATWG Infra Standard.

Requirement

Base64.Decoder and Base64.Encoder classes, and Base64 static class

| Chrome | Edge | Firefox | Safari | Deno | Node.js | | :---: | :---: | :---: | :---: | :---: | :---: | | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |

Base64.DecoderStream and Base64.EncoderStream classes

These require TransformStream.

| Chrome | Edge | Firefox | Safari | Deno | Node.js | | :---: | :---: | :---: | :---: | :---: | :---: | | ✅ | ✅ | ✅102+ | ✅14.1+ | ✅ | ✅16.5+ |

Installation

npm

$ npm i @i-xi-dev/[email protected]
import { Base64 } from "@i-xi-dev/base64";

CDN

Example for UNPKG

import { Base64 } from "https://www.unpkg.com/@i-xi-dev/[email protected]/esm/mod.js";

Usage

Base64.Decoder and Base64.Encoder classes, and Base64 static class

const decoder = new Base64.Decoder();

decoder.decode("AwIBAP/+/fw=");
// → Uint8Array[ 0x03, 0x02, 0x01, 0x00, 0xFF, 0xFE, 0xFD, 0xFC ]
const encoder = new Base64.Encoder();

encoder.encode(Uint8Array.of(0x03, 0x02, 0x01, 0x00, 0xFF, 0xFE, 0xFD, 0xFC));
// → "AwIBAP/+/fw="
Base64.decode("AwIBAP/+/fw=");
// → Uint8Array[ 0x03, 0x02, 0x01, 0x00, 0xFF, 0xFE, 0xFD, 0xFC ]
Base64.encode(Uint8Array.of(0x03, 0x02, 0x01, 0x00, 0xFF, 0xFE, 0xFD, 0xFC));
// → "AwIBAP/+/fw="

Base64.DecoderStream and Base64.EncoderStream classes

const decoderStream = new Base64.DecoderStream();

// readableStream: ReadableStream<string>
// writableStream: WritableStream<Uint8Array>
readableStream.pipeThrough(decoderStream).pipeTo(writableStream);
const encoderStream = new Base64.EncoderStream();

// readableStream: ReadableStream<Uint8Array>
// writableStream: WritableStream<string>
readableStream.pipeThrough(encoderStream).pipeTo(writableStream);

Encoding options

See the documentation

Example

The options for Base 64 Encoding with URL and Filename Safe Alphabet, defined in RFC 4648

// use the predefined Base64.Options
const rfc4648urlOptions = Base64.Options.RFC4648URL;

const decoder = new Base64.Decoder(rfc4648urlOptions);
const encoder = new Base64.Encoder(rfc4648urlOptions);
const decoderStream = new Base64.DecoderStream(rfc4648urlOptions);
const encoderStream = new Base64.EncoderStream(rfc4648urlOptions);
const decoded = Base64.decode(str, rfc4648urlOptions);
const encoded = Base64.encode(uint8Array, rfc4648urlOptions);
// create Base64.Options
const rfc4648urlOptions = {
  /*
  rawTable: [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_" ],
  */
  tableLastChars: ["-", "_"],
  noPadding: true,
};

const decoder = new Base64.Decoder(rfc4648urlOptions);
const encoder = new Base64.Encoder(rfc4648urlOptions);
const decoderStream = new Base64.DecoderStream(rfc4648urlOptions);
const encoderStream = new Base64.EncoderStream(rfc4648urlOptions);
const decoded = Base64.decode(str, rfc4648urlOptions);
const encoded = Base64.encode(uint8Array, rfc4648urlOptions);

Examples