const exampleSchema = type({
"type": type("string").narrow((n, ctx) => {
const forbiddenStrings = ctx.meta.forbiddenStrings;
if (forbiddenStrings.includes(n)) {
return ctx.reject("string must NOT be one of the following: " + forbiddenStrings.join(", "));
}
return true;
})
});
function validate(data: unknown, forbiddenStrings: string[]): void {
const validated = exampleSchema(data, { forbiddenStrings }); // provide forbidden strings to the schema
}
const exampleSchema = type({
"type": type("string").narrow((n, ctx) => {
const forbiddenStrings = ctx.meta.forbiddenStrings;
if (forbiddenStrings.includes(n)) {
return ctx.reject("string must NOT be one of the following: " + forbiddenStrings.join(", "));
}
return true;
})
});
function validate(data: unknown, forbiddenStrings: string[]): void {
const validated = exampleSchema(data, { forbiddenStrings }); // provide forbidden strings to the schema
}