https://github.com/duzun/base64util
base64 encode/decode utility for browsers and node.js
https://github.com/duzun/base64util
Last synced: 3 months ago
JSON representation
base64 encode/decode utility for browsers and node.js
- Host: GitHub
- URL: https://github.com/duzun/base64util
- Owner: duzun
- License: mit
- Created: 2015-10-13T07:43:30.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T18:05:47.000Z (almost 2 years ago)
- Last Synced: 2025-06-13T21:06:29.500Z (4 months ago)
- Language: JavaScript
- Homepage: https://duzun.me/playground/encode#base64UrlEncode=https%3A%2F%2Fgithub.com%2Fduzun%2Fbase64util
- Size: 604 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# base64util [](https://travis-ci.com/duzun/base64util) [](https://codecov.io/gh/duzun/base64util)
base64 encode/decode utility for browsers and node.js,
with polyfill and URL friendly format.Works with multi-byte and utf8 [strings](https://github.com/duzun/string-encode.js#the-theory-of-string-).
## Usage
### Include [`base64`](https://unpkg.com/base64util) the way you like (AMD/CommonJs/script)
```js
// Encodes multi-byte string as utf8 to base64 (common String)
base64.encode('plain') ;// Decodes to multi-byte string if utf8-encoded as base64
base64.decode('base64');// same as encode/decode, but instead of "/" and "+" uses "_" and "-" (URL friendly)
base64.urlEncode('plain') ;
base64.urlDecode('base64');// encode/decode byte-string - 8bit per char - used for binary data
base64.byteEncode('plain') ;
base64.byteDecode('base64');// Encode byte-string for URL
base64.byteUrlEncode('plain') ;
base64.byteUrlDecode('base64');
```### Polyfill
```js
if ( typeof atob === 'undefined' ) {
var window.atob = base64._atob;
var window.btoa = base64._btoa;
}
```or
```js
base64.polyfill(window);
```### String.prototype methods
```js
// Add String.prototype methods:
bindProto(String.prototype)'plain'.base64ByteEncode() ;
'base64'.base64ByteDecode();'plain'.base64Encode() ;
'base64'.base64Decode();'plain'.base64ByteUrlEncode() ;
'base64'.base64ByteUrlDecode();'plain'.base64UrlEncode() ;
'base64'.base64UrlDecode();```