From cd59075921c620d5d8a628b599027fe463203502 Mon Sep 17 00:00:00 2001 From: Avior Date: Wed, 2 Apr 2025 11:13:15 +0200 Subject: [PATCH] feat: add the `in` check --- src/SchemaItem.ts | 11 +++++++++++ src/items/enum.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/SchemaItem.ts b/src/SchemaItem.ts index b4d343d..1ef8d70 100644 --- a/src/SchemaItem.ts +++ b/src/SchemaItem.ts @@ -83,6 +83,17 @@ export default abstract class SchemaItem 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): this { + this.addValidation((input) => values.includes(input)) + + return this + } + public attrs(...attributes: Array) { this.attributes.concat(attributes) return this diff --git a/src/items/enum.ts b/src/items/enum.ts index ad1adc0..5e3e005 100644 --- a/src/items/enum.ts +++ b/src/items/enum.ts @@ -18,7 +18,7 @@ export default class SchemaEnum extends SchemaItem Object.values(this.templateEnum).includes(input), error: `Input is not part of ${templateEnum.constructor.name}`