Compare commits

..

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

8 changed files with 39 additions and 119 deletions

View File

@ -1,49 +1,30 @@
atob atob
=== ===
| **atob**
| [btoa](https://git.coolaj86.com/coolaj86/btoa.js)
| [unibabel.js](https://git.coolaj86.com/coolaj86/unibabel.js)
| Sponsored by [ppl](https://ppl.family)
Uses `Buffer` to emulate the exact functionality of the browser's atob. Uses `Buffer` to emulate the exact functionality of the browser's atob.
Note: Unicode may be handled incorrectly (like the browser). Note: Unicode may be handled incorrectly (like the browser).
It turns base64-encoded <strong>a</strong>scii data back **to** <strong>b</strong>inary. It turns base64-encoded <strong>a</strong>scii data back **to** <strong>b</strong>inary.
```javascript
(function () { (function () {
"use strict"; "use strict";
var atob = require('atob'); var atob = require('atob')
var b64 = "SGVsbG8sIFdvcmxkIQ=="; , b64 = "SGVsbG8gV29ybGQ="
var bin = atob(b64); , bin = atob(b64)
;
console.log(bin); // "Hello, World!" console.log(bin); // "Hello World"
}()); }());
```
### Need Unicode and Binary Support in the Browser?
Check out [unibabel.js](https://git.coolaj86.com/coolaj86/unibabel.js)
Changelog
=======
* v2.1.0 address a few issues and PRs, update URLs
* v2.0.0 provide browser version for ios web workers
* v1.2.0 provide (empty) browser version
* v1.1.3 add MIT license
* v1.1.2 node only
LICENSE LICENSE
======= =======
Code copyright 2012-2018 AJ ONeal Code copyright 2012-2015 AJ ONeal
Dual-licensed MIT and Apache-2.0 Dual-licensed MIT and Apache-2.0
Docs copyright 2012-2018 AJ ONeal Docs copyright 2012-2015 AJ ONeal
Docs released under [Creative Commons](https://git.coolaj86.com/coolaj86/atob.js/blob/master/LICENSE.DOCS). Docs released under [Creative Commons](https://github.com/node-browser-compat/atob/blob/master/LICENSE.DOCS).

View File

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

View File

@ -1,24 +0,0 @@
{
"name": "atob",
"description": "atob for isomorphic environments",
"main": "browser-atob.js",
"authors": [
"AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com)"
],
"license": "(MIT OR Apache-2.0)",
"keywords": [
"atob",
"browser"
],
"homepage": "https://github.com/node-browser-compat/atob",
"moduleType": [
"globals"
],
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}

View File

@ -1,44 +0,0 @@
(function (w) {
"use strict";
function findBest(atobNative) {
// normal window
if ('function' === typeof atobNative) { return atobNative; }
// browserify (web worker)
if ('function' === typeof Buffer) {
return function atobBrowserify(a) {
//!! Deliberately using an API that's deprecated in node.js because
//!! this file is for browsers and we expect them to cope with it.
//!! Discussion: github.com/node-browser-compat/atob/pull/9
return new Buffer(a, 'base64').toString('binary');
};
}
// ios web worker with base64js
if ('object' === typeof w.base64js) {
// bufferToBinaryString
// https://git.coolaj86.com/coolaj86/unibabel.js/blob/master/index.js#L50
return function atobWebWorker_iOS(a) {
var buf = w.base64js.b64ToByteArray(a);
return Array.prototype.map.call(buf, function (ch) {
return String.fromCharCode(ch);
}).join('');
};
}
return function () {
// ios web worker without base64js
throw new Error("You're probably in an old browser or an iOS webworker." +
" It might help to include beatgammit's base64-js.");
};
}
var atobBest = findBest(w.atob);
w.atob = atobBest;
if ((typeof module === 'object') && module && module.exports) {
module.exports = atobBest;
}
}(window));

9
index.js Normal file
View File

@ -0,0 +1,9 @@
(function () {
"use strict";
function atob(str) {
return new Buffer(str, 'base64').toString('binary');
}
module.exports = atob;
}());

View File

@ -1,7 +0,0 @@
"use strict";
function atob(str) {
return Buffer.from(str, 'base64').toString('binary');
}
module.exports = atob.atob = atob;

View File

@ -1,24 +1,23 @@
{ {
"name": "atob", "name": "atob",
"homepage": "https://git.coolaj86.com/coolaj86/atob.js.git", "homepage": "https://github.com/coolaj86/node-browser-compat",
"description": "atob for Node.JS and Linux / Mac / Windows CLI (it's a one-liner)", "description": "atob for Node.JS and Linux / Mac / Windows CLI (it's a one-liner)",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://git.coolaj86.com/coolaj86/atob.js.git" "url": "git://github.com/coolaj86/node-browser-compat.git"
}, },
"keywords": [ "keywords": [
"atob", "atob",
"browser" "browser"
], ],
"author": "AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com)", "author": "AJ ONeal <coolaj86@gmail.com> (http://coolaj86.info)",
"engines": { "engines": {
"node": ">= 4.5.0" "node": ">= 0.4.0"
}, },
"main": "node-atob.js", "main": "index",
"browser": "browser-atob.js",
"bin": { "bin": {
"atob": "bin/atob.js" "atob": "bin/atob.js"
}, },
"license": "(MIT OR Apache-2.0)", "license": "(MIT OR Apache-2.0)",
"version": "2.1.2" "version": "1.1.3"
} }

View File

@ -1,13 +1,15 @@
/*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 atob = require('.'); var atob = require('./index')
var encoded = "SGVsbG8sIFdvcmxkIQ==" , encoded = "SGVsbG8gV29ybGQ="
var unencoded = "Hello, World!"; , unencoded = "Hello World"
/* /*
, encoded = "SGVsbG8sIBZM" , encoded = "SGVsbG8sIBZM"
, unencoded = "Hello, 世界" , unencoded = "Hello, 世界"
*/ */
;
if (unencoded !== atob(encoded)) { if (unencoded !== atob(encoded)) {
console.log('[FAIL]', unencoded, atob(encoded)); console.log('[FAIL]', unencoded, atob(encoded));