MyGit

v0.21.0

fabian-hiller/valibot

版本发布时间: 2023-11-19 22:59:15

fabian-hiller/valibot最新发布版本:v1.0.0-beta.0-i18n(2024-10-02 12:06:55)

Many thanks to @Saeris, @lo1tuma, @david-plugge, @ciscoheat, @kazizi55 and @BastiDood for contributing to this release.

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.

相关地址:原始地址 下载(tar) 下载(zip)

查看:2023-11-19发行的版本