Compare commits

...

2 Commits

Author SHA1 Message Date
a7a20f55f4
0.1.0 2025-04-02 11:13:23 +02:00
cd59075921
feat: add the in check 2025-04-02 11:13:15 +02:00
4 changed files with 15 additions and 4 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@dzeio/schema",
"version": "0.0.6",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@dzeio/schema",
"version": "0.0.6",
"version": "0.1.0",
"dependencies": {
"@dzeio/object-util": "^1.8.3",
"@standard-schema/spec": "^1.0.0",

View File

@ -1,6 +1,6 @@
{
"name": "@dzeio/schema",
"version": "0.0.6",
"version": "0.1.0",
"dependencies": {
"@dzeio/object-util": "^1.8.3"
},

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}`