b64u-lite
isomorphic base64url library in 358 bytes
Last updated 5 years ago by kevlened .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install b64u-lite 
SYNC missed versions from official npm registry.

b64u-lite NPM Build bundlephobia

isomorphic base64url library in 244 bytes

Usage

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!

import { toBase64Url } from 'b64u-lite'

License

MIT

Current Tags

  • 1.1.0                                ...           latest (5 years ago)

4 Versions

  • 1.1.0                                ...           5 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
  • 0.0.2                                ...           7 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (1)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE