Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: es6 base64 parser #75

Merged
merged 2 commits into from
Apr 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions lib/formats/base64.js
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM but I don’t think the intermediary payloadToParse variable is really necessary is it? It would work just fine as

payload =  this.decorator.parse(payload);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I wasn't changing any of the code functionality in the PR. Here I just renamed the variable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure - just seems that if the whole file is being changed anyway, why not make this minor optimization. Not a biggie.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just going to focus this PR and other PRs on converting this file to es6 and not changing the functionality. I'd rather do that in a different PR.

}

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;