special

Creates a special schema.

This schema function allows you to define a schema that matches a value based on a custom function. Use it whenever you need to define a schema that cannot be expressed using any of the other schema functions.

// Special schema with an optional pipe
const Schema = special<TInput>(check, pipe);

// Special schema with an optional message and pipe
const Schema = special<TInput>(check, message, pipe);

Generics

  • TInput extends any

Parameters

  • check (input: unknown) => boolean
  • message ErrorMessage | undefined
  • pipe Pipe<TInput> | undefined

Explanation

With special you can validate the data type of the input and with pipe you can transform and validate the further details of the input. If the input does not match the validation of check, you can use message to customize the error message.

Make sure that the validation in check matches the data type of TInput.

Returns

Examples

The following examples show how special can be used.

Pixel string schema

Schema to validate a pixel string.

const PixelStringSchema = special<`${number}px`>((val) =>
  typeof val === 'string' ? /^\d+px$/.test(val) : false
);

The following APIs can be combined with special.

Schemas

Methods

Transformations

Validations

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of fabian-hiller

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of dailydotdev
  • GitHub profile picture of ivan-mihalic
  • GitHub profile picture of KATT
  • GitHub profile picture of osdiab
  • GitHub profile picture of Thanaen
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of caegdeveloper