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

@jsonjoy.com/base64

v1.1.2

Published

High-performance Base64 encoder and decoder

Downloads

6,689,398

Readme

Base64

Fast Base64 encoder and decoder for browser and Node.js.

Encoder

  • Implements Base64 encoding algorithm compatible with Node's Buffer.
  • Isomorphic—it can be used in, both, Node and the browser.
  • Faster than the Node's implementation for short blobs, smaller than 40 bytes.
  • Uses Node's implementation for long blobs, if available. Hence, it also works in browser, but in Node environment will perform faster for short strings.
  • Can encode into Base64 text or Base64 Uint8Array.

Usage

Use encoder compatible with Node's Buffer:

import {toBase64} from '@jsonjoy.com/base64';

toBase64(new Uint8Array([1, 2, 3]));

Create your custom encoder:

import {createToBase64} from '@jsonjoy.com/base64';

const encode = createToBase64('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_');

encode(new Uint8Array([1, 2, 3]));

Benchmark

Below benchmark encodes random binary blobs of sizes 8, 16, 32, 64, 128, 256, 512, and 1024 byes. @jsonjoy.com/base64 is faster, because for short strings (less than 40 chars) it uses a native JavaScript implementation, which is faster and also works in browsers. For blobs larger than 40 chars, it falls back to Node Buffer implementation, if available.

Encoding:

node src/__bench__/encode.js
util/base64 toBase64(uint8) x 1,531,283 ops/sec ±0.30% (92 runs sampled), 653 ns/op
util/base64 createToBase64()(uint8) x 946,364 ops/sec ±0.76% (100 runs sampled), 1057 ns/op
js-base64 x 1,103,190 ops/sec ±1.27% (96 runs sampled), 906 ns/op
fast-base64-encode x 500,225 ops/sec ±0.64% (96 runs sampled), 1999 ns/op
base64-js x 328,368 ops/sec ±0.25% (95 runs sampled), 3045 ns/op
Buffer.from(uint8).toString('base64'); x 1,099,420 ops/sec ±0.20% (100 runs sampled), 910 ns/op
Fastest is util/base64 toBase64(uint8)

Decoding:

node src/__bench__/decode.js
@jsonjoy.com/base64 fromBase64(str) x 756,989 ops/sec ±0.46% (97 runs sampled), 1321 ns/op
@jsonjoy.com/base64 createFromBase64()(str) x 475,591 ops/sec ±0.37% (96 runs sampled), 2103 ns/op
Buffer.from(str, 'base64') x 545,012 ops/sec ±0.33% (101 runs sampled), 1835 ns/op
base64-js x 487,015 ops/sec ±1.19% (94 runs sampled), 2053 ns/op
js-base64 x 173,049 ops/sec ±0.20% (99 runs sampled), 5779 ns/op
Fastest is @jsonjoy.com/base64 fromBase64(str)

Decoder

  • Uses Node.js built-in Buffer, if available.
  • When Buffer is not available, uses JavaScript implementation.

Usage

Use decoder compatible with Node's Buffer:

import {toBase64, fromBase64} from '@jsonjoy.com/base64';

fromBase64(toBase64(new Uint8Array([1, 2, 3])));

Create your custom encoder:

import {createFromBase64} from '@jsonjoy.com/base64';

const decoder = createFromBase64('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+_');

decoder(toBase64(new Uint8Array([1, 2, 3])));