Additional validators for class-validator.
- π΅οΈββοΈ Thoroughly tested
- π Well documented
- β¨ No additional dependencies (Day.js is supported but optional)
- π Uses Semantic Versioning and keeps a nice Changelog
Use your favorite package manager to install:
npm install class-validator-extended
For obvious reasons, class-validator needs to be installed.
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.
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. | π |