decode base64

This commit is contained in:
Daniel Odendahl Jr
2018-03-12 18:38:56 +00:00
parent 3a14617543
commit ab8c828b2c
3 changed files with 20 additions and 6 deletions
+4 -2
View File
@@ -54,8 +54,10 @@ class Util {
return arr;
}
static base64(text) {
return Buffer.from(text).toString('base64');
static base64(text, mode = 'encode') {
if (mode === 'encode') return Buffer.from(text).toString('base64');
if (mode === 'decode') return Buffer.from(text, 'base64').toString('utf8');
throw new TypeError(`${mode} is not a supported base64 mode.`);
}
static hash(text, algorithm) {