Skip to content

Instantly share code, notes, and snippets.

@pavelvlasov
Created January 21, 2018 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavelvlasov/8384479b8f3766e751de63ad06b7699b to your computer and use it in GitHub Desktop.
Save pavelvlasov/8384479b8f3766e751de63ad06b7699b to your computer and use it in GitHub Desktop.
html to png validate body
interface Body {
html: string;
width: number;
height: number;
name: string;
}
const validateBody = (body: any): Body => {
if (typeof body.html !== "string") {
throw new Error("Unsupported html type");
}
if (typeof body.width !== "number" && typeof body.height !== "number") {
throw new Error("Unsupported dimensions");
}
if (typeof body.name !== "string" && !body.name) {
throw new Error("Name should be of type string and not empty");
}
return body as Body;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment