Skip to main content

before

npm Package Size Security Scorecard CI

Use this wrapper to transform or validate input before schema validation.

import {before, string} from '@livon/schema';

const UserName = before({
schema: string().min(2),
hook: (input) => {
if (typeof input === 'string') {
return input.trim();
}
return input;
},
});

const value = UserName.parse(' alice ');

before can wrap any value schema from this section.
API schemas (api) are not valid as before.schema.

Parameters

  • schema (Schema<T>, required): wrapped schema.
  • hook ((input, ctx) => SchemaHookBeforeResult, required): pre-parse hook.

Chain API

  • No schema-specific chain methods.
  • Shared methods on current type T = schema output: optional(): Schema<T | undefined>, nullable(): Schema<T | null>, describe(doc: SchemaDoc): Schema<T>, refine(input): Schema<T>, before(hook): Schema<T>, after<U>(hook): Schema<U>, and<U>(other: Schema<U>, options?: {name?: string}): Schema<T & U>.