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

feat: ts formatter #210

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/lib/formats/base64.js → src/lib/formats/base64.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
class Base64Parser {
constructor(decorator) {
decorator: any;

constructor(decorator: any) {
this.decorator = decorator;
}

parse(payload) {
parse(payload: any): any {
let payloadToParse = payload;
if (this.decorator) {
payloadToParse = this.decorator.parse(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ class JSONFormatter {
* Every internal data structure is JSON by nature, so
* no transformation is required
*/
format(payload) {
format(payload: any) {
lance marked this conversation as resolved.
Show resolved Hide resolved
return payload;
}

toString(payload) {
toString(payload: any) {
return JSON.stringify(payload);
}
}

module.exports = JSONFormatter;
export default JSONFormatter;
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ const {
isString,
isDefinedOrThrow,
isStringOrObjectOrThrow
} = require("../../bindings/http/validation/fun.js");
} = require("../../bindings/http/validation/fun");
const ValidationError = require("../../bindings/http/validation/validation_error.js");

const invalidPayloadTypeError = new ValidationError("invalid payload type, allowed are: string or object");
const nullOrUndefinedPayload = new ValidationError("null or undefined payload");

const asJSON = (v) => (isString(v) ? JSON.parse(v) : v);
const asJSON = (v: object|string) => (isString(v) ? JSON.parse(v as string) : v);

class JSONParser {
constructor(decorator) {
decorator: any
constructor(decorator: Base64Parser) {
this.decorator = decorator;
}

Expand All @@ -20,7 +21,7 @@ class JSONParser {
* @param {object|string} payload the JSON payload
* @return {object} the parsed JSON payload.
*/
parse(payload) {
parse(payload: object|string) {
if (this.decorator) {
payload = this.decorator.parse(payload);
}
Expand Down