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

@waiting/base64

v4.2.9

Published

Base64 encoding/decoding in pure JS on both modern Browsers and Node.js. Also supports URL-safe base64

Downloads

864

Readme

base64

Base64 encoding/decoding in pure JS on both modern Browsers and Node.js based on base64-js.
Also supports URL-safe base64

Version License Build Status Build status Coverage Status Conventional Commits

Features

  • Supports typeof string, number and bigint
  • Supports ArrayBuffer or Uint8Array
  • Encoding/Decoding via TextEncoder/TextDecoder under browser and Buffer under Node.js
  • Building various modulesESM, UMD and CJS

Browser requirement

Node.js requirement

  • v10.4.0+ for bigint base64 encoding
  • ICU installation for base64 decoding with char encodings other then utf-8 and utf-16le

Installing

npm install @waiting/base64

Usage of Node.js

See the Docs for details

Encoding

import { b64encode, b64fromBuffer, b64urlEncode } from '@waiting/base64'

b64encode('A') === 'QQ=='
b64encode('schöne') === 'c2Now7ZuZQ=='
b64encode(1n) === b64encode(1) // bigint -> 'MQ==' 
b64encode('𠮷') === b64encode('\uD842\uDFB7') === b64encode('\u{20BB7}') // '8KCutw=='

const u8arr = Uint8Array.from([0xe4, 0xb8, 0xad, 0xe6, 0x96, 0x87])
b64fromBuffer(u8arr) === b64encode('中文')  // '5Lit5paH'

// URL-safe
b64urlEncode('A') === 'QQ'
b64urlEncode('中文测试') === '5Lit5paH5rWL6K-V'

Decoding

import { b64decode, b64urlDecode } from '@waiting/base64'

b64decode('MQ==') === '1'
b64urlDecode('MQ') === '1'

Transfer

import { b64toURLSafe, b64fromURLSafe } from '@waiting/base64'

// base64 -> URL-safe base64
b64toURLSafe('QQ==') === 'QQ'
b64toURLSafe('5Lit5paH5rWL6K+V') === '5Lit5paH5rWL6K-V'

// URL-safe base64 -> base64
b64fromURLSafe('QQ') === 'QQ=='
b64fromURLSafe('0J_RgNC40LLQtdGCLCDQvNC40YAh') === '0J/RgNC40LLQtdGCLCDQvNC40YAh'

Usage of browser

See the Docs for details

ESM

<script type="module">
  import { b64encode, b64urlEncode } from './base64.esm.min.js' 
  
  console.log( b64encode('A') ) // 'QQ=='
  console.log( b64urlEncode('A') )  // 'QQ'
  console.log( b64encode('\uD842\uDFB7') ) // '8KCutw=='
</script>

UMD

<!-- polyfill for Edge
  Note: text-encoder-lite parse 4-bytes UTF-8 char incorrectly,
  so use text-encoding instead.
  see: https://github.com/solderjs/TextEncoderLite/issues/16
-->
<!--
<script src="https://raw.githubusercontent.com/inexorabletash/text-encoding/master/lib/encoding-indexes.js"></script>
<script src="https://raw.githubusercontent.com/inexorabletash/text-encoding/master/lib/encoding.js"></script>
-->
<script src="./base64.umd.min.js"></script>
<script>
  // global variable base64
  console.log( base64.b64encode('A') )
  console.log( base64.b64urlEncode('A') )
  console.log( base64.b64encode('\uD842\uDFB7') )
</script>

Testing

npm run test

# for browsers FireFox and Chrome
npm run test:browser

# for browsers all available on this client
cd .config && npm i
npm run browser:detect

Demo

License

MIT

Languages