From ca6ee6b95bd0b43fe61a692197490015b70dc4ac Mon Sep 17 00:00:00 2001 From: Grant Timmerman Date: Tue, 28 Apr 2020 21:11:01 -0700 Subject: [PATCH] feat: es6 base64 parser Signed-off-by: Grant Timmerman --- lib/formats/base64.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/formats/base64.js b/lib/formats/base64.js index 2e2ef4bc..cd73def6 100644 --- a/lib/formats/base64.js +++ b/lib/formats/base64.js @@ -1,15 +1,16 @@ +class Base64Parser { + constructor(decorator) { + this.decorator = decorator; + } -function Parser(decorator) { - this.decorator = decorator; -} + parse(payload) { + let payloadToParse = payload; + if (this.decorator) { + payloadToParse = this.decorator.parse(payload); + } -Parser.prototype.parse = function(payload) { - let toparse = payload; - if (this.decorator) { - toparse = this.decorator.parse(payload); + return Buffer.from(payloadToParse, "base64").toString(); } +} - return Buffer.from(toparse, "base64").toString(); -}; - -module.exports = Parser; +module.exports = Base64Parser;