feat: add split feature to array

This commit is contained in:
Florian Bouillon 2025-04-02 13:02:20 +02:00
parent 476a17be17
commit fdfaac9aa0
Signed by: Florian Bouillon
GPG Key ID: 7676FF78F3BC40EC

View File

@ -15,6 +15,14 @@ export default class SchemaArray<Type extends SchemaItem> extends SchemaItem<Arr
return this return this
} }
/**
* split a string into an array
* @param [separator] default:`,` the separator to use
*/
public split(separator = ',') {
this.addPreProcess((it) => typeof it === 'string' ? it.split(separator) : it)
}
public parse(input: unknown, options?: { fast?: boolean }): ValidationResult<Array<SchemaInfer<Type>>> { public parse(input: unknown, options?: { fast?: boolean }): ValidationResult<Array<SchemaInfer<Type>>> {
// check errors from itself // check errors from itself