# abab

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

Latest version **2.0.6** (published 2022-04-17) · BSD-3-Clause license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install abab
pnpm add abab
yarn add abab
bun add abab
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.6 |
| Published | 2022-04-17 |
| First published | 2015-09-01 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 91 |
| Author | Jeff Carpenter |
| Maintainers | jeffcarp |
| Keywords | atob, btoa, browser |

## Links

- npm: https://www.npmjs.com/package/abab
- Repository: https://github.com/jsdom/abab
- Homepage: https://github.com/jsdom/abab#readme
- Issues: https://github.com/jsdom/abab/issues
- npm.io page: https://npm.io/package/abab

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.0.6 (latest) — 2022-04-17
- 2.0.5 — 2020-09-11
- 2.0.4 — 2020-08-01
- 2.0.3 — 2019-11-13
- 2.0.2 — 2019-09-24
- 2.0.1 — 2019-08-28
- 2.0.0 — 2018-04-20
- 1.0.4 — 2017-09-21
- 1.0.3 — 2016-01-12
- 1.0.2 — 2015-12-30
- 1.0.1 — 2015-11-13
- 1.0.0 — 2015-09-01

## README

# abab [![npm version](https://badge.fury.io/js/abab.svg)](https://www.npmjs.com/package/abab) [![Build Status](https://travis-ci.org/jsdom/abab.svg?branch=master)](https://travis-ci.org/jsdom/abab)

A JavaScript module that implements `window.atob` and `window.btoa` according the forgiving-base64 algorithm in the [Infra Standard](https://infra.spec.whatwg.org/#forgiving-base64). The original code was forked from [w3c/web-platform-tests](https://github.com/w3c/web-platform-tests/blob/master/html/webappapis/atob/base64.html).

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

Install with `npm`:

```sh
npm install abab
```

## API

### `btoa` (base64 encode)

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

### `atob` (base64 decode)

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

#### Valid characters

[Per the spec](https://html.spec.whatwg.org/multipage/webappapis.html#atob:dom-windowbase64-btoa-3), `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.

```js
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](CONTRIBUTING.md#checklists).

## Remembering what `atob` and `btoa` stand for

Base64 comes from IETF [RFC 4648](https://tools.ietf.org/html/rfc4648#section-4) (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.

---
_Source: https://npm.io/package/abab · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
