JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 19819058
  • Score
    100M100P100Q41336F
  • License ISC

WHATWG spec-compliant implementations of window.atob and window.btoa.

Package Exports

  • abab
  • abab/lib/atob
  • abab/lib/btoa

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (abab) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

abab

npm version Build Status

A module that implements window.atob and window.btoa according to the WHATWG spec. The code is originally from w3c/web-platform-tests.

Compatibility: Node.js version 3+ and all major browsers (using browserify or webpack)

Install with npm:

npm install abab

API

btoa (base64 encode)

const btoa = require('abab').btoa;
btoa('Hello, world!'); // 'SGVsbG8sIHdvcmxkIQ=='

atob (base64 decode)

const atob = require('abab').atob;
atob('SGVsbG8sIHdvcmxkIQ=='); // 'Hello, world!'

Valid characters

Per the spec, btoa will accept strings "containing only characters in the range U+0000 to U+00FF." If passed a string with characters above U+00FF, btoa will return null. If atob is passed a string that is not base64-valid, it will also return null. In both cases when null is returned, the spec calls for throwing a DOMException of type InvalidCharacterError.

Browsers

If you want to include just one of the methods to save bytes in your client-side code, you can require the desired module directly.

var atob = require('abab/lib/atob');
var btoa = require('abab/lib/btoa');

Checklists

If you're submitting a PR or deploying to npm, please use the checklists in CONTRIBUTING.md

Remembering atob vs. btoa

Here's a mnemonic that might be useful: if you have a plain string and want to base64 encode it, then decode it, btoa is what you run before (before - btoa), and atob is what you run after (after - atob).