Compare commits

...

15 Commits

Author SHA1 Message Date
755cfea789 v2.1.2: remove version field from bower 2018-08-18 04:18:47 -06:00
ca87d10534 remove version (should rely on tags instead) 2018-08-18 10:17:02 +00:00
AJ ONeal
e468cb840c v2.1.1 fix https://github.com/nodejs/security-wg/pull/211 2018-04-27 11:33:56 -06:00
AJ ONeal
2a8151a1d2 v2.1.0 2018-03-27 22:26:00 -06:00
AJ ONeal
599c6330b9 v2.0.3 2016-04-09 15:29:39 -06:00
AJ ONeal
372a2dff10 Merge pull request #5 from robertknight/browserify-fix
Fix atob under CommonJS module bundlers (eg. Browserify)
2016-04-09 15:29:04 -06:00
AJ ONeal
21542879a8 v2.0.2 2016-04-09 15:28:20 -06:00
AJ ONeal
8a691b4548 Merge pull request #7 from Supporting/patch-1
Fix for browsers supporting a2b
2016-04-09 15:26:18 -06:00
Kristian Sons
2dd6aa1c2c Fix for browsers supporting a2b
Argument passed to a2b should be the ascii string.
2016-04-09 12:02:37 +02:00
Robert Knight
50cb9f059a Fix atob under CommonJS module bundlers (eg. Browserify)
Browserify uses the browser version of the module but since
module.exports was not assigned, importing it fails.

 * Fix a typo in the browser implementation of 'browser-atob'

 * Fix reference to the source file in the tests

 * Export 'atob' implementation in 'browser-atob.js' via module
   exports
2015-12-28 09:59:15 +00:00
AJ ONeal
f6c7618c46 Update README.md 2015-12-14 11:46:48 -08:00
AJ ONeal
394c0c0afb v2.0.1 2015-12-12 06:58:00 -08:00
AJ ONeal
cc8e518d66 add bower.json 2015-12-12 06:57:47 -08:00
AJ ONeal
1dcd72793e Update README.md 2015-12-11 20:59:12 -08:00
AJ ONeal
eb52ffbd7e Update README.md 2015-12-11 20:58:29 -08:00
6 changed files with 90 additions and 45 deletions

View File

@ -1,38 +1,49 @@
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.
Note: Unicode may be handled incorrectly (like the browser).
It turns base64-encoded <strong>a</strong>scii data back **to** <strong>b</strong>inary.
(function () {
"use strict";
```javascript
(function () {
"use strict";
var atob = require('atob')
, b64 = "SGVsbG8gV29ybGQ="
, bin = atob(b64)
;
var atob = require('atob');
var b64 = "SGVsbG8sIFdvcmxkIQ==";
var bin = atob(b64);
console.log(bin); // "Hello World"
}());
console.log(bin); // "Hello, World!"
}());
```
Changes
### 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 (see [#4](https://github.com/node-browser-compat/atob/issues/4))
* v1.1.3 add MIT license
* v1.1.2 node only
LICENSE
=======
Code copyright 2012-2015 AJ ONeal
Code copyright 2012-2018 AJ ONeal
Dual-licensed MIT and Apache-2.0
Docs copyright 2012-2015 AJ ONeal
Docs copyright 2012-2018 AJ ONeal
Docs released under [Creative Commons](https://github.com/node-browser-compat/atob/blob/master/LICENSE.DOCS).
Docs released under [Creative Commons](https://git.coolaj86.com/coolaj86/atob.js/blob/master/LICENSE.DOCS).

24
bower.json Normal file
View File

@ -0,0 +1,24 @@
{
"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,32 +1,44 @@
(function (w) {
"use strict";
var a2b = w.atob;
function atob(str) {
function findBest(atobNative) {
// normal window
if ('function' === typeof a2b) {
return a2b(a2b);
}
// browserify (web worker)
else if ('function' === typeof Buffer) {
return new Buffer(str, 'base64').toString('binary');
}
// ios web worker with base64js
else if ('object' === typeof w.base64js) {
// bufferToBinaryString
// https://github.com/coolaj86/unibabel-js/blob/master/index.js#L50
var buf = w.base64js.b64ToByteArray(str);
if ('function' === typeof atobNative) { return atobNative; }
return Array.prototype.map.call(buf, function (ch) {
return String.fromCharCode(ch);
}).join('');
// 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 without base64js
else {
throw new Error("you're probably in an ios webworker. please include use beatgammit's base64-js");
// 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.");
};
}
w.atob = atob;
var atobBest = findBest(w.atob);
w.atob = atobBest;
if ((typeof module === 'object') && module && module.exports) {
module.exports = atobBest;
}
}(window));

View File

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

View File

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

View File

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