Many thanks to @Saeris, @lo1tuma, @david-plugge, @ciscoheat, @kazizi55 and @BastiDood for contributing to this release.
- Change structure of schemas, validations and transformations to make properties accessible (pull request #211)
- Fix errors in JSDoc comments and add JSDoc ESLint plugin (pull request #205)
- Fix missing file extension for Deno (pull request #249)
Migration guide
The internal structure of schema and pipeline functions has changed as a result of #211. These changes affect people who have created their own schema, validation, or transformation functions.
import { type BaseValidation, type ErrorMessage, getOutput, getPipeIssues } from 'valibot';
// Change this
export function minLength<TInput extends string | any[]>(
requirement: number,
error?: ErrorMessage
) {
return (input: TInput): PipeResult<TInput> =>
input.length < requirement
? getPipeIssues('min_length', error || 'Invalid length', input)
: getOutput(input);
}
// To that
export type MinLengthValidation<
TInput extends string | any[],
TRequirement extends number
> = BaseValidation<TInput> & {
type: 'min_length';
requirement: TRequirement;
};
export function minLength<
TInput extends string | any[],
TRequirement extends number
>(
requirement: TRequirement,
message: ErrorMessage = 'Invalid length'
): MinLengthValidation<TInput, TRequirement> {
return {
type: 'min_length',
async: false,
message,
requirement,
_parse(input) {
return input.length < this.requirement
? getPipeIssues(this.type, this.message, input, this.requirement)
: getOutput(input);
},
};
}
If you have any questions or problems, please have a look at the source code or create an issue. I usually respond within 24 hours.