abab

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

Use your platform's native atob() and btoa() methods instead
Last updated 3 years ago by jeffcarp .
BSD-3-Clause · Repository · Bugs · Original npm · Tarball · package.json
$ npm install abab 
SYNC missed versions from official npm registry.

abab npm version Build Status

A JavaScript module that implements window.atob and window.btoa according the forgiving-base64 algorithm in the Infra Standard. The original code was forked from w3c/web-platform-tests.

Compatibility: Node.js version 3+ and all major browsers.

Install with npm:

npm install abab

API

btoa (base64 encode)

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

atob (base64 decode)

const { atob } = require('abab');
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.

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

Development

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

Remembering what atob and btoa stand for

Base64 comes from IETF RFC 4648 (2006).

  • btoa, the encoder function, stands for binary to ASCII, meaning it converts any binary input into a subset of ASCII (Base64).
  • atob, the decoder function, converts ASCII (or Base64) to its original binary format.

Current Tags

  • 2.0.6                                ...           latest (3 years ago)

12 Versions

  • 2.0.6 [deprecated]           ...           3 years ago
  • 2.0.5 [deprecated]           ...           4 years ago
  • 2.0.4 [deprecated]           ...           4 years ago
  • 2.0.3 [deprecated]           ...           5 years ago
  • 2.0.2 [deprecated]           ...           5 years ago
  • 2.0.1 [deprecated]           ...           5 years ago
  • 2.0.0 [deprecated]           ...           7 years ago
  • 1.0.4 [deprecated]           ...           7 years ago
  • 1.0.3 [deprecated]           ...           9 years ago
  • 1.0.2 [deprecated]           ...           9 years ago
  • 1.0.1 [deprecated]           ...           9 years ago
  • 1.0.0 [deprecated]           ...           9 years ago
Maintainers (1)
Downloads
Total 6
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (8)

© 2010 - cnpmjs.org x YWFE | Home | YWFE