https://github.com/un-ts/ab64
The smallest and fastest Base64 implementation in JavaScript based on `atob` and `btoa` from browser native or `Buffer` from node
https://github.com/un-ts/ab64
base64 base64-decoding base64-encoding base64url js-base64
Last synced: 7 months ago
JSON representation
The smallest and fastest Base64 implementation in JavaScript based on `atob` and `btoa` from browser native or `Buffer` from node
- Host: GitHub
- URL: https://github.com/un-ts/ab64
- Owner: un-ts
- License: mit
- Created: 2022-07-30T02:43:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-06-30T07:33:03.000Z (8 months ago)
- Last Synced: 2025-07-07T15:35:35.366Z (7 months ago)
- Topics: base64, base64-decoding, base64-encoding, base64url, js-base64
- Language: TypeScript
- Homepage: https://ab64.js.org
- Size: 874 KB
- Stars: 12
- Watchers: 0
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ab64
[](https://github.com/un-ts/ab64/actions/workflows/ci.yml?query=branch%3Amain)
[](https://codecov.io/gh/un-ts/ab64)
[](https://github.com/plantain-00/type-coverage)
[](https://coderabbit.ai)
[](https://www.npmjs.com/package/ab64)
[](https://github.com/un-ts/ab64/releases)
[](https://conventionalcommits.org)
[](https://renovatebot.com)
[](https://standardjs.com)
[](https://github.com/prettier/prettier)
[](https://github.com/changesets/changesets)
The smallest and fastest Base64 implementation in JavaScript based on `atob` and `btoa` from browser native or `Buffer` from node
## TOC
- [Usage](#usage)
- [Install](#install)
- [API](#api)
- [Basic](#basic)
- [Polyfill](#polyfill)
- [Ponyfill](#ponyfill)
- [MiniApp (WeChat)](#miniapp-wechat)
- [Sponsors and Backers](#sponsors-and-backers)
- [Sponsors](#sponsors)
- [Backers](#backers)
- [Changelog](#changelog)
- [License](#license)
## Usage
### Install
```sh
# pnpm
pnpm add ab64
# yarn
yarn add ab64
# npm
npm i ab64
```
### API
#### Basic
```js
import { decode, decodeUrl, encode, encodeUrl } from 'ab64'
encode('Hello World!') // SGVsbG8gV29ybGQh
encode('dankogai') // ZGFua29nYWk=
encodeUrl('dankogai') // ZGFua29nYWk
encode('小飼弾') // 5bCP6aO85by+
encodeUrl('小飼弾') // 5bCP6aO85by-
decode('SGVsbG8gV29ybGQh') // Hello World!
decode('ZGFua29nYWk=') // dankogai
decodeUrl('ZGFua29nYWk') // dankogai
decode('5bCP6aO85by+') // 小飼弾
decodeUrl('5bCP6aO85by-') // 小飼弾
```
#### Polyfill
If you're running on a non Node environment where `atob` and `btoa` could be unavailable, you may want to include the `polyfill` manually
```js
import 'ab64/polyfill'
// same as above then
```
#### Ponyfill
`atob` and `btoa` are also available exported as `ab64/ponyfill` which does not polyfill by default
```js
import { atob, btoa } from 'ab64/ponyfill'
// same as browser native
```
#### MiniApp (WeChat)
Since mini app (from wechat) does not support global polyfill, so you have to use the separate `mini-app` entry instead which uses the above ponyfill inside
```js
import { decode, decodeUrl, encode, encodeUrl } from 'ab64/mini-app'
```
Or you should add an alias mapping `ab64` to `ab64/mini-app` in your `rollup`/`vite`/`webpack` configuration
## Sponsors and Backers
[](https://github.com/sponsors/JounQin)
### Sponsors
| 1stG | RxTS | UnTS |
| ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unts) |
### Backers
| 1stG | RxTS | UnTS |
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unts) |
## Changelog
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
## License
[MIT][] © [JounQin][]@[1stG.me][]
[1stg.me]: https://www.1stg.me
[jounqin]: https://GitHub.com/JounQin
[mit]: http://opensource.org/licenses/MIT