Skip to content
/ abab Public
forked from jsdom/abab

Perfectly spec-compliant atob and btoa implementations

Notifications You must be signed in to change notification settings

bevacqua/abab

 
 

Repository files navigation

abab

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

Compatibility: io.js (all major versions), 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.

Contributing

Ideas

  • If we can set up browser testing (Sauce?), would be cool to test against every browser's implementation of atob/btoa

About

Perfectly spec-compliant atob and btoa implementations

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%