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

base64-encoding

v0.15.0-alpha.0

Published

Fast Base64 encoding and decoding powered by WebAssembly.

Downloads

617

Readme

Base64 Encoding

Fast Base64 encoding and decoding powered by WebAssembly.

This library is modeled after the WHATWG TextEncoder and TextDecoder API, providing a Base64Encoder and Base64Decoder class.

The C implementation was chosen based on benchmarks provided by gaspardpetit/base64.

Usage

const encoder = await new Base64Encoder().optimize();
encoder.encode(new TextEncoder().encode('foobar'))   // => Zm9vYmFy

const decoder = await new Base64Decoder().optimize();
new TextDecoder().decode(decoder.decode("Zm9vYmFy")) // => foobar

For one-shot usage, you can use the JS implementation without instantiating a WASM instance:

new Base64Encoder().encode(new TextEncoder().encode('foobar'))   // => Zm9vYmFy
new TextDecoder().decode(new Base64Decoder().decode("Zm9vYmFy")) // => foobar

URL-friendly Encoding

This implementation also supports a URL-friendly variant of Base64, where

  • all '+' are mapped to '-'
  • all '/' are mapped to '_'
  • the padding characters '=' are omitted

To use this variant, provide the url setting when creating the encoder.

const encoder = await new Base64Encoder({ url: true }).optimize();

For decoding URL-friendly Base64 no extra steps are required.

Performance

TBD

Currently only the encoder provides a significant performance improvement over the pure JS implementation.

Distribution

This module is published on npm under the base64-encoding tag. The package contains the following:

  • The root folder (Browse) exports ES modules in ES2018 syntax. All internal module paths are fully qualified, so they can be imported in Deno or the browser directly:

    import * as b64 from 'https://unpkg.com/base64-encoding?module';
  • The module folder (Browse) contains a rolled-up version of the above.

    import * as b64 from 'https://unpkg.com/base64-encoding/module';
  • The cjs folder (Browse) exports CommonJS modules in ES2015 syntax for use in node.

    require('base64-encoding')
  • The src folder (Browse) contains the TypeScript source code.

The root and cjs folder include type declarations and source maps, so that IntelliSense works out of the box in VSCode.

The package.json properly sets the main, module, type and exports keys, so that package.json-based tools will pick the right version.

License

TBD

Currently the C code is licensed under an ancient Apache 1.0 license that comes with some pretty old-school requirements, such as including the following in all promotional materials:

This product includes software developed by the Apache Group for use in the Apache HTTP server project (http://www.apache.org/).

It is very likely that ap_base64.c has been shipped under a Apache-2.0 license somewhere. Once I locate it, this requirement will go away.

TODO

  • Figure out why decoding is slow
  • License