How to validate base64? #1446
Answered
by
jsjoeio
gustavotoyota
asked this question in
Q&A
-
Very simple problem, but can't find any info anywhere. |
Beta Was this translation helpful? Give feedback.
Answered by
jsjoeio
Feb 26, 2023
Replies: 2 comments 5 replies
-
Did you ever figure out a solution? |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
gustavotoyota
-
For the record, this can now be easily done using import { z } from "zod";
const validateAndParseBase64 = z
.string()
.base64()
.transform((val: string) => Buffer.from(val, "base64").toString("utf-8"));
console.log(validateAndParseBase64.parse("aGVsbG8gd29ybGQ="));
validateAndParseBase64.parse("should fail"); // will throw |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you ever figure out a solution?