Compare commits

..

No commits in common. "master" and "v1.1.2" have entirely different histories.

4 changed files with 27 additions and 34 deletions

View File

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

View File

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

View File

@ -2,12 +2,13 @@
"use strict"; "use strict";
function btoa(str) { function btoa(str) {
var buffer; var buffer
;
if (str instanceof Buffer) { if (str instanceof Buffer) {
buffer = str; buffer = str;
} else { } else {
buffer = Buffer.from(str.toString(), 'binary'); buffer = new Buffer(str.toString(), 'binary');
} }
return buffer.toString('base64'); return buffer.toString('base64');

View File

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