diff --git a/atob/index.js b/atob/index.js index 65bfaf5..72ddb40 100644 --- a/atob/index.js +++ b/atob/index.js @@ -2,7 +2,7 @@ "use strict"; function atob(str) { - return new Buffer(str, 'utf8').toString('base64'); + return new Buffer(str, 'base64').toString('utf8'); } module.exports = atob; diff --git a/atob/test.js b/atob/test.js index 65fb01d..38e5ffe 100644 --- a/atob/test.js +++ b/atob/test.js @@ -2,11 +2,12 @@ "use strict"; var atob = require('./index') - , expected = "SGVsbG8gV29ybGQ=" + , encoded = "SGVsbG8gV29ybGQ=" + , unencoded = "Hello World" , result ; - if (expected !== atob("Hello World")) { + if (unencoded !== atob(encoded)) { return; } diff --git a/btoa/index.js b/btoa/index.js new file mode 100644 index 0000000..8bfc1ad --- /dev/null +++ b/btoa/index.js @@ -0,0 +1,9 @@ +(function () { + "use strict"; + + function btoa(str) { + return new Buffer(str, 'utf8').toString('base64'); + } + + module.exports = btoa; +}()); diff --git a/btoa/package.json b/btoa/package.json new file mode 100644 index 0000000..4ff5854 --- /dev/null +++ b/btoa/package.json @@ -0,0 +1,18 @@ +{ + "name" : "btoa", + "homepage" : "https://github.com/coolaj86/node-browser-compat", + "description" : "btoa for Node.JS (it's a one-liner)", + "repository" : { + "type": "git", + "url": "git://github.com/coolaj86/node-browser-compat.git" + }, + "keywords" : ["btoa", "browser"], + "author" : "AJ ONeal (http://coolaj86.info)", + "engines" : { + "node": ">= 0.4.0" + }, + "dependencies" : { + }, + "main" : "index", + "version" : "1.0.0" +} diff --git a/btoa/test.js b/btoa/test.js new file mode 100644 index 0000000..e0122a2 --- /dev/null +++ b/btoa/test.js @@ -0,0 +1,15 @@ +(function () { + "use strict"; + + var btoa = require('./index') + , encoded = "SGVsbG8gV29ybGQ=" + , unencoded = "Hello World" + , result + ; + + if (encoded !== btoa(unencoded)) { + return; + } + + console.log('[PASS] all tests pass'); +}());