https://github.com/kevlened/b64u-lite
:anchor: isomorphic base64url library in 531 bytes
https://github.com/kevlened/b64u-lite
base64url isomorphic javascript small
Last synced: 11 months ago
JSON representation
:anchor: isomorphic base64url library in 531 bytes
- Host: GitHub
- URL: https://github.com/kevlened/b64u-lite
- Owner: kevlened
- License: mit
- Created: 2018-01-07T03:01:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T10:37:46.000Z (over 3 years ago)
- Last Synced: 2024-11-07T19:23:33.061Z (over 1 year ago)
- Topics: base64url, isomorphic, javascript, small
- Language: JavaScript
- Homepage:
- Size: 121 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# b64u-lite [](https://npmjs.com/package/b64u-lite) [](https://travis-ci.org/kevlened/b64u-lite) [](https://bundlephobia.com/result?p=b64u-lite)
Node, browser, and React Native base64url library
## Usage
```javascript
const b64u = require('b64u-lite');
b64u.toBase64Url('hi there? 你好');
// aGkgdGhlcmU_IOS9oOWlvQ
// add padding
b64u.toBase64Url('hi there? 你好', true);
// aGkgdGhlcmU_IOS9oOWlvQ==
// convert a buffer to b64u
b64u.toBase64Url(new Uint8Array([228, 189, 160, 229, 165, 189]).buffer);
// 5L2g5aW9
// convert b64u to a buffer
b64u.toBuffer('5L2g5aW9');
// new Uint8Array([228, 189, 160, 229, 165, 189]).buffer
// works with or without padding
b64u.fromBase64Url('aGkgdGhlcmU_IOS9oOWlvQ==');
b64u.fromBase64Url('aGkgdGhlcmU_IOS9oOWlvQ');
// hi there? 你好
// equivalent to btoa
b64u.fromBinaryString('hi there? ');
// aGkgdGhlcmU_IA
// with padding
b64u.fromBinaryString('hi there? ', true);
// aGkgdGhlcmU_IA==
// equivalent to atob
b64u.toBinaryString('aGkgdGhlcmU=');
// hi there?
```
## Can it be smaller?
If you use ES6 imports with a bundler that supports tree-shaking, yes!
```javascript
import { toBase64Url } from 'b64u-lite'
```
## License
MIT