class-validator-extended

Additional validators for class-validator.


Keywords
validator, validation, decorators, typescript, class-validator, plugin
License
MIT
Install
npm install class-validator-extended@3.0.0

Documentation

Typescript npm GitHub Workflow Status GitHub Issues libraries.io Codecov npm bundle size

class-validator-extended

Additional validators for class-validator.

Safe and simple to use

Installation

Use your favorite package manager to install:

npm install class-validator-extended

For obvious reasons, class-validator needs to be installed.

Usage

Just use the decorators like any of the built-in ones:

import { ArrayMinSize } from 'class-validator'
import { ArrayMonotonic } from 'class-validator-extended'

class Foo {
    @ArrayMinSize(2)
    @ArrayMonotonic()
    values: [1, 13, 42]
}

If you don't have Dayjs installed you need to use the minimal export:

import { MaxBigInt } from 'class-validator-extended/dist/minimal'

Please note that Dayjs is an optional dependency and will by default be installed by npm and yarn. To avoid this use npm install --omit optional or yarn install --ignore-optional, respectively.

Validation decorators

For detailed information please read the API docs.

Decorator Description API
Type
@IsBigInt(options?) Checks if the given value is a BigInt. πŸ”—
@IsDayjs(options?) Checks if the given value is a valid Dayjs object. πŸ”—
@IsDuration(options?) Checks if the given value is a valid Dayjs duration. πŸ”—
@IsNull(options?) Checks if the given value is null. πŸ”—
@IsMap(options?) Checks if the given value is a Map. πŸ”—
@IsSet(options?) Checks if the given value is a Set. πŸ”—
Common
@Nullable(options?) Only validates the given value if it is not null. πŸ”—
@Optional(options?) Only validates the given value if it is not undefined. πŸ”—
Array
@ArrayMonotonic(options?) Checks if the given value is an array sorted in either (strictly) ascending or (strictly) descending order. πŸ”—
@ArraySize(size, options?) Checks if the given value is an array with exactly size elements. πŸ”—
BigInt
@MaxBigInt(maximum, options?) Checks if the given value is a BigInt not greater than maximum. πŸ”—
@MinBigInt(minimum, options?) Checks if the given value is a BigInt not less than minimum. πŸ”—
@NegativeBigInt(options?) Checks if the given value is a BigInt less than zero. πŸ”—
@PositiveBigInt(options?) Checks if the given value is a BigInt greater than zero. πŸ”—
Date
@FutureDate(options?) Checks if the given value is a Date object in the future. πŸ”—
@PastDate(options?) Checks if the given value is a Date object in the past. πŸ”—
Dayjs
@FutureDayjs(options?) Checks if the given value is a valid Dayjs object in the future. πŸ”—
@MaxDayjs(maximum, options?) Checks if the given value is a valid Dayjs object not later than maximum. πŸ”—
@MaxDuration(minimum, options?) Checks if the given value is a valid Dayjs duration not longer than maximum. πŸ”—
@MinDayjs(minimum, options?) Checks if the given value is a valid Dayjs object not earlier than minimum. πŸ”—
@MinDuration(minimum, options?) Checks if the given value is a valid Dayjs duration not shorter than minimum. πŸ”—
@PastDayjs(options?) Checks if the given value is a valid Dayjs object in the past. πŸ”—
Map
@MapContains(required, options?) Checks if the given value is a Map and contains all required values. πŸ”—
@MapContainsKeys(required, options?) Checks if the given value is a Map and contains all required keys. πŸ”—
@MapMaxSize(maximum, options?) Checks if the given value is a Map with no more than maximum entries. πŸ”—
@MapMinSize(minimum, options?) Checks if the given value is a Map with no fewer than minimum entries. πŸ”—
@MapNotContains(forbidden, options?) Checks if the given value is a Map which does not contain any of the forbidden values. πŸ”—
@MapNotContainsKeys(forbidden, options?) Checks if the given value is a Map which does not contain any of the forbidden keys. πŸ”—
@MapNotEmpty(options?) Checks if the given value is a Map with at least one entry. πŸ”—
@MapSize(size, options?) Checks if the given value is a Map with exactly size entries. πŸ”—
@MapUnique(projection, options?) Checks if the given value is a Map without duplicates with regard to the given projection. πŸ”—
@MapUniqueKeys(projection, options?) Checks if the given value is a Map whose keys are all unique with regard to the given projection. πŸ”—
Number
@IsNetworkPort(options?) Checks if the given value is a valid port number. πŸ”—
Set
@SetContains(required, options?) Checks if the given value is a Set and contains all required values. πŸ”—
@SetMaxSize(maximum, options?) Checks if the given value is a Set with no more than maximum values. πŸ”—
@SetMinSize(minimum, options?) Checks if the given value is a Set with no fewer than minimum values. πŸ”—
@SetNotContains(forbidden, options?) Checks if the given value is a Set which does not contain any of the forbidden values. πŸ”—
@SetSize(size, options?) Checks if the given value is a Set with exactly size entries. πŸ”—
@SetNotEmpty(options?) Checks if the given value is a Set with at least one value. πŸ”—
@SetUnique(projection, options?) Checks if the given value is a Set without duplicate values with regard to the given projection. πŸ”—
String
@IsAwsRegion(options?) Checks if the given value is an AWS region string. πŸ”—
@IsAwsARN(options?) Checks if the given value is an AWS ARN string. πŸ”—
@NotMatches(pattern, modifiers?, options?) Checks if the given value is an string that does not match the given regular expression. πŸ”—