Skip to content

Commit

Permalink
feat: add polyfill and ponyfill support (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored Jul 31, 2022
1 parent c50de7c commit a5d5d7c
Show file tree
Hide file tree
Showing 13 changed files with 249 additions and 108 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-pumpkins-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ab64": minor
---

feat: add polyfill and ponyfill support
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/changesets/changesets)

The smallest and fastest Base64 implementation in JavaScript
The smallest and fastest Base64 implementation in JavaScript based on `atob` and `btoa` from browser native or `Buffer` from node

## TOC <!-- omit in toc -->

- [Usage](#usage)
- [Install](#install)
- [API](#api)
- [Basic](#basic)
- [Polyfill](#polyfill)
- [Ponyfill](#ponyfill)
- [Sponsors](#sponsors)
- [Backers](#backers)
- [Changelog](#changelog)
Expand All @@ -42,6 +45,8 @@ npm i ab64

### API

#### Basic

```js
import { decode, decodeUrl, encode, encodeUrl } from 'ab64'

Expand All @@ -62,6 +67,26 @@ 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
```

## Sponsors

| 1stG | RxTS | UnTS |
Expand Down
29 changes: 20 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@
},
"funding": "https://opencollective.com/unts",
"license": "MIT",
"packageManager": "[email protected].0",
"packageManager": "[email protected].1",
"engines": {
"node": "^12.20.0 || ^14.18.0 || >=16.0.0"
},
"exports": "./src/index.ts",
"exports": {
".": "./src/index.ts",
"./ponyfill": "./src/ponyfill.ts"
},
"files": [
"lib",
"!**/*.tsbuildinfo"
Expand Down Expand Up @@ -91,9 +94,9 @@
"@changesets/cli": "^2.24.1",
"@pkgr/webpack": "^3.2.0",
"@pkgr/webpack-mdx": "^2.0.3",
"@size-limit/preset-small-lib": "^7.0.8",
"@size-limit/preset-small-lib": "^8.0.0",
"@types/mdx": "^2.0.2",
"@types/node": "^18.6.2",
"@types/node": "^18.6.3",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"@types/web": "^0.0.70",
Expand All @@ -105,7 +108,7 @@
"react-dom": "^18.2.0",
"react-router-dom": "^6.3.0",
"sirv-cli": "^2.0.2",
"size-limit": "^7.0.8",
"size-limit": "^8.0.0",
"type-coverage": "^2.22.0",
"typescript": "4.7.4",
"unplugin-auto-import": "^0.10.3",
Expand All @@ -115,17 +118,25 @@
"main": "./lib/index.cjs",
"module": "./lib/index.js",
"exports": {
"types": "./lib/index.d.ts",
"browser": "./lib/browser.js",
"import": "./lib/index.js",
"require": "./lib/index.cjs"
".": {
"types": "./lib/index.d.ts",
"browser": "./lib/browser.js",
"import": "./lib/index.js",
"require": "./lib/index.cjs"
},
"./polyfill": "./lib/polyfill.js",
"./ponyfill": "./lib/ponyfill.js"
},
"types": "./lib/index.d.ts"
},
"size-limit": [
{
"path": "lib/browser.js",
"limit": "280B"
},
{
"path": "lib/ponyfill.js",
"limit": "520B"
}
],
"typeCoverage": {
Expand Down
Loading

0 comments on commit a5d5d7c

Please sign in to comment.