This commit is contained in:
AJ ONeal 2018-03-27 22:44:53 -06:00
parent 625d3f256f
commit aedf7281e7
4 changed files with 32 additions and 24 deletions

View File

@ -1,30 +1,40 @@
btoa
===
| [atob](https://git.coolaj86.com/coolaj86/atob.js)
| **btoa**
| [unibabel.js](https://git.coolaj86.com/coolaj86/unibabel.js)
| Sponsored by [ppl](https://ppl.family)
A port of the browser's `btoa` function.
Uses `Buffer` to emulate the exact functionality of the browser's btoa (except that it supports unicode and the browser may not).
Uses `Buffer` to emulate the exact functionality of the browser's btoa
(except that it supports some unicode that the browser may not).
It turns <strong>b</strong>inary data __to__ base64-encoded <strong>a</strong>scii.
(function () {
"use strict";
var btoa = require('btoa')
, bin = "Hello, 世界"
, b64 = btoa(bin)
;
```js
(function () {
"use strict";
console.log(b64); // "SGVsbG8sIBZM"
}());
var btoa = require('btoa');
var bin = "Hello, 世界";
var b64 = btoa(bin);
Note: Unicode may or may not be handled incorrectly.
console.log(b64); // "SGVsbG8sIBZM"
}());
```
Copyright and license
**Note**: Unicode may or may not be handled incorrectly.
This module is intended to provide exact compatibility with the browser.
Copyright and License
===
Code and documentation copyright 2012-2014 AJ ONeal Tech, LLC.
Code copyright 2012-2018 AJ ONeal
Code released under the [Apache license](https://github.com/node-browser-compat/btoa/blob/master/LICENSE).
Dual-licensed MIT and Apache-2.0
Docs released under [Creative Commons](https://github.com/node-browser-compat/btoa/blob/master/LICENSE.DOCS).
Docs copyright 2012-2018 AJ ONeal
Docs released under [Creative Commons](https://git.coolaj86.com/coolaj86/btoa.js/blob/master/LICENSE.DOCS).

View File

@ -1,10 +1,8 @@
#!/usr/bin/env node
/*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true*/
(function () {
"use strict";
var btoa = require('../index')
;
var btoa = require('../index');
console.log(btoa(process.argv[2]));
}());

View File

@ -7,7 +7,7 @@
if (str instanceof Buffer) {
buffer = str;
} else {
buffer = new Buffer(str.toString(), 'binary');
buffer = Buffer.from(str.toString(), 'binary');
}
return buffer.toString('base64');

View File

@ -1,16 +1,16 @@
{
"name": "btoa",
"homepage": "https://github.com/coolaj86/node-browser-compat",
"homepage": "https://git.coolaj86.com/coolaj86/btoa.js.git",
"description": "btoa for Node.JS (it's a one-liner)",
"repository": {
"type": "git",
"url": "git://github.com/coolaj86/node-browser-compat.git"
"url": "git://git.coolaj86.com/coolaj86/btoa.js.git",
},
"keywords": [
"btoa",
"browser"
],
"author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info)",
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com)",
"engines": {
"node": ">= 0.4.0"
},
@ -18,6 +18,6 @@
"btoa": "bin/btoa.js"
},
"main": "index",
"license": "Apache-2.0",
"version": "1.1.2"
"license": "(MIT OR Apache-2.0)",
"version": "1.2.0"
}