From 50cb9f059a0ef5af46d5449528d826c6ac9c00cc Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Mon, 28 Dec 2015 09:54:13 +0000 Subject: [PATCH] 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 --- browser-atob.js | 6 +++++- test.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/browser-atob.js b/browser-atob.js index 95ff45b..f5fc8bc 100644 --- a/browser-atob.js +++ b/browser-atob.js @@ -6,7 +6,7 @@ function atob(str) { // normal window if ('function' === typeof a2b) { - return a2b(a2b); + return a2b(str); } // browserify (web worker) else if ('function' === typeof Buffer) { @@ -29,4 +29,8 @@ } w.atob = atob; + + if (typeof module !== 'undefined') { + module.exports = atob; + } }(window)); diff --git a/test.js b/test.js index f8903d0..e499dd5 100644 --- a/test.js +++ b/test.js @@ -2,7 +2,7 @@ (function () { "use strict"; - var atob = require('./index') + var atob = require('.') , encoded = "SGVsbG8gV29ybGQ=" , unencoded = "Hello World" /*