fixed mixup of atob / btoa
This commit is contained in:
		
							parent
							
								
									6de6b3935a
								
							
						
					
					
						commit
						0eb1226e1d
					
				@ -2,7 +2,7 @@
 | 
				
			|||||||
  "use strict";
 | 
					  "use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  function atob(str) {
 | 
					  function atob(str) {
 | 
				
			||||||
    return new Buffer(str, 'utf8').toString('base64');
 | 
					    return new Buffer(str, 'base64').toString('utf8');
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  module.exports = atob;
 | 
					  module.exports = atob;
 | 
				
			||||||
 | 
				
			|||||||
@ -2,11 +2,12 @@
 | 
				
			|||||||
  "use strict";
 | 
					  "use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  var atob = require('./index')
 | 
					  var atob = require('./index')
 | 
				
			||||||
    , expected = "SGVsbG8gV29ybGQ="
 | 
					    , encoded = "SGVsbG8gV29ybGQ="
 | 
				
			||||||
 | 
					    , unencoded = "Hello World"
 | 
				
			||||||
    , result
 | 
					    , result
 | 
				
			||||||
    ;
 | 
					    ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (expected !== atob("Hello World")) {
 | 
					  if (unencoded !== atob(encoded)) {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										9
									
								
								btoa/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								btoa/index.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					(function () {
 | 
				
			||||||
 | 
					  "use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  function btoa(str) {
 | 
				
			||||||
 | 
					    return new Buffer(str, 'utf8').toString('base64');
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  module.exports = btoa;
 | 
				
			||||||
 | 
					}());
 | 
				
			||||||
							
								
								
									
										18
									
								
								btoa/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								btoa/package.json
									
									
									
									
									
										Normal file
									
								
							@ -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 <coolaj86@gmail.com> (http://coolaj86.info)",
 | 
				
			||||||
 | 
					  "engines"       : {
 | 
				
			||||||
 | 
					                      "node": ">= 0.4.0"
 | 
				
			||||||
 | 
					                    },
 | 
				
			||||||
 | 
					  "dependencies"  : {
 | 
				
			||||||
 | 
					                    },
 | 
				
			||||||
 | 
					  "main"          : "index",
 | 
				
			||||||
 | 
					  "version"       : "1.0.0"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										15
									
								
								btoa/test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								btoa/test.js
									
									
									
									
									
										Normal file
									
								
							@ -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');
 | 
				
			||||||
 | 
					}());
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user