feat: Filemagedon
Some checks failed
Build, check & Test / run (push) Failing after 1m45s
Lint / run (push) Failing after 48s
Build Docker Image / build_docker (push) Failing after 3m18s

Signed-off-by: Avior <git@avior.me>
This commit is contained in:
2024-09-11 14:38:58 +02:00
parent 3e91597dca
commit bc97d9106b
45 changed files with 4548 additions and 64 deletions

View File

@ -0,0 +1,76 @@
import SchemaItem from '../SchemaItem'
import SchemaNullable from './SchemaNullable'
export default class SchemaString extends SchemaItem<string> {
/**
* force the input text to be a minimum of `value` size
* @param value the minimum length of the text
* @param message the message to display on an error
*/
public min(value: number, message?: string): SchemaString {
this.validations.push({
fn(input) {
return input.length >= value
},
message: message
})
return this
}
/**
* force the input text to be a maximum of `value` size
* @param value the maximum length of the text
* @param message the message to display on an error
*/
public max(value: number, message?: string): SchemaString {
this.validations.push({
fn(input) {
return input.length <= value
},
message: message
})
return this
}
/**
* the value must not be empty (`''`)
* @param message
* @returns
*/
public notEmpty(message?: string): this {
this.validations.push({
fn(input) {
return input !== ''
},
message: message
})
return this
}
/**
* note: this nullable MUST be used last as it change the type of the returned function
*/
public nullable() {
return new SchemaNullable(this)
}
/**
* force the input text to respect a Regexp
* @param regex the regex to validate against
* @param message the message to display on an error
*/
public regex(regex: RegExp, message?: string): SchemaString {
this.validations.push({
fn(input) {
return regex.test(input)
},
message
})
return this
}
public override isOfType(input: unknown): input is string {
return typeof input === 'string'
}
}