Created
December 19, 2019 07:49
-
-
Save DawnImpulse/e89275206bcc5ddb4387fce8e326f341 to your computer and use it in GitHub Desktop.
riteway + @hapi/joi
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
describe("uuid()", async (assert) => { | |
assert({ | |
given: "nothing", | |
should: "generate a 32 chars alphanumeric string", | |
actual: validate( | |
generate.uuid(), | |
Joi.string() | |
.alphanum() | |
.length(32), | |
), | |
expected: true, | |
}); | |
}); | |
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
// this code is in typescript (you can avoid types in javascript) | |
import { AnySchema } from "@hapi/joi"; | |
export default function validate<T>(value: T, schema: AnySchema): boolean { | |
const { error } = schema.validate(value); | |
return error == undefined; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment