forked from luisbrito/api.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing BasicAuth by adding a compatibility layer for base64 conversion.
btoa is only available on browsers: nodejs/node#3462
- Loading branch information
Showing
2 changed files
with
26 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
/** | ||
* Abstraction layer for string to base64 conversion | ||
* reference: https://github.com/nodejs/node/issues/3462 | ||
*/ | ||
class Base64 { | ||
/** | ||
* Creates a base-64 encoded ASCII string from a "string" of binary data. | ||
* @param {string} string to be encoded. | ||
* @return {string} | ||
* @static | ||
*/ | ||
static encodeString(string) { | ||
if (typeof btoa === 'function') { | ||
return btoa(string); | ||
} | ||
|
||
return new Buffer(string.toString(), 'binary'); | ||
} | ||
} | ||
|
||
export default Base64; |