feat: add the in check

This commit is contained in:
Florian Bouillon 2025-04-02 11:13:15 +02:00
parent a0cc29169d
commit cd59075921
Signed by: Florian Bouillon
GPG Key ID: 7676FF78F3BC40EC
2 changed files with 12 additions and 1 deletions

View File

@ -83,6 +83,17 @@ export default abstract class SchemaItem<Type = any> implements StandardSchemaV1
return this
}
/**
* make sure the value is one of the `values`
* @param values the values the item MUST contains
*/
@parceable()
public in(...values: Array<Type>): this {
this.addValidation((input) => values.includes(input))
return this
}
public attrs(...attributes: Array<string>) {
this.attributes.concat(attributes)
return this

View File

@ -18,7 +18,7 @@ export default class SchemaEnum<E extends EnumLike> extends SchemaItem<E[keyof E
this.type = 'number'
}
// test above === numebr
// test above === number
this.validations.push({
fn: (input) => Object.values(this.templateEnum).includes(input),
error: `Input is not part of ${templateEnum.constructor.name}`