From c3c29706f68528196af03ac3d025530be51a6776 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 9 Sep 2011 14:56:22 -0600 Subject: [PATCH] fixed mixup of atob / btoa --- index.js | 9 +++++++++ package.json | 18 ++++++++++++++++++ test.js | 15 +++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 index.js create mode 100644 package.json create mode 100644 test.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..8bfc1ad --- /dev/null +++ b/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/package.json b/package.json new file mode 100644 index 0000000..4ff5854 --- /dev/null +++ b/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/test.js b/test.js new file mode 100644 index 0000000..e0122a2 --- /dev/null +++ b/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'); +}());