Created
January 21, 2018 03:43
-
-
Save pavelvlasov/8384479b8f3766e751de63ad06b7699b to your computer and use it in GitHub Desktop.
html to png validate body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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