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
===
| [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 some unicode that the browser may not).
Uses `Buffer` to emulate the exact functionality of the browser's btoa (except that it supports unicode and 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 () {
"use strict";
(function () {
"use strict";
var btoa = require('btoa');
var bin = "Hello, 世界";
var b64 = btoa(bin);
var btoa = require('btoa')
, bin = "Hello, 世界"
, b64 = btoa(bin)
;
console.log(b64); // "SGVsbG8sIBZM"
}());
```
console.log(b64); // "SGVsbG8sIBZM"
}());
**Note**: Unicode may or may not be handled incorrectly.
This module is intended to provide exact compatibility with the browser.
Note: Unicode may or may not be handled incorrectly.
Copyright and License
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://git.coolaj86.com/coolaj86/btoa.js/blob/master/LICENSE.DOCS).
Docs released under [Creative Commons](https://github.com/node-browser-compat/btoa/blob/master/LICENSE.DOCS).

View File

@ -1,8 +1,10 @@
#!/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

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

View File

@ -1,16 +1,16 @@
{
"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)",
"repository": {
"type": "git",
"url": "git://git.coolaj86.com/coolaj86/btoa.js.git"
"url": "git://github.com/coolaj86/node-browser-compat.git"
},
"keywords": [
"btoa",
"browser"
],
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com)",
"author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info)",
"engines": {
"node": ">= 0.4.0"
},
@ -18,6 +18,6 @@
"btoa": "bin/btoa.js"
},
"main": "index",
"license": "(MIT OR Apache-2.0)",
"version": "1.2.1"
"license": "Apache2",
"version": "1.1.2"
}