Generic class-validator options.
Checks if the given value is a Dayjs object.
Note that dayjs
is not a constructor, so you can't simply use @IsInstance(Dayjs)
.
// Ensure the value is a Dayjs object.
@IsDayjs()
dateOfBirth: Dayjs
Accepts the following options (in addition to generic class-validator options):
is_valid: boolean = true
If true, checks that the Dayjs object is valid.Checks if the given value is a Dayjs Duration object.
This requires the Duration-plugin to be loaded. If this is not the case, an error will be thrown.
// Ensure the value is a Dayjs Duration object.
@IsDuration()
value: Duration
Generic class-validator options.
Checks if the given value is an array sorted in either (strictly) ascending or (strictly) descending order.
This validator will always pass if the given value is an empty array.
// Ensure the array is sorted in reverse order of dates of birth.
@ArrayMonotonic({
monotonicity: Monotonicity.WEAKLY_DECREASING,
projection: (user: User) => user.dateOfBirth.getTime()
})
users: User[]
// Ensure the array is sorted in ascending order, allowing no duplicates.
@ArrayMonotonic({
monotonicity: Monotonicity.STRICTLY_INCREASING,
comparator: (a, b) => a - b
})
values: number[]
The type of the array elements.
Accepts the following options (in addition to generic class-validator options):
monotonicity: Monotonicity
The required ordering of the array.projection: (element) => number
(mutually exclusive with comparator
)
Project an array element to a number which is then used for comparison.comparator: (a, b) => number
(mutually exclusive with projection
)
Directly compare two elements (as in Array.sort).Checks if the given value is a BigInt
not greater than maximum
.
// Ensure the value is less than 9000.
@MaxBigInt(8_999)
underNineThousand: BigInt
The maximum allowed value.
Generic class-validator options.
Checks if the given value is a BigInt
not less than minimum
.
// Ensure the value is greater than 9000.
@MinBigInt(9_001)
overNineThousand: BigInt
The minimum allowed value.
Generic class-validator options.
Checks if the given value is a Date object in the future.
Beware that the behaviour of this check depends on the current time and can thus be difficult to test. In particular, as time goes by the property can become invalid without ever changing its value.
// Ensure the value is in the future.
@FutureDay()
scheduledFor: Date
Generic class-validator options.
Checks if the given value is a Date object in the past.
Beware that the behaviour of this check depends on the current time and can thus be difficult to test.
// Ensure the value is in the past.
@PastDate()
created: Date
Generic class-validator options.
Checks if the given value is a Dayjs object in the future.
Beware that the behaviour of this check depends on the current time and can thus be difficult to test. In particular, as time goes by the property can become invalid without ever changing its value.
// Ensure the value is in the future.
@FutureDayjs()
scheduledFor: Dayjs
Generic class-validator options.
Checks if the given value is a Dayjs object not later than maximum
.
// Ensure the value is before the infamous Y2K.
@MaxDayjs('2000-01-01T00:00:00.000Z')
y2kSafeDate: Dayjs
The maximum allowed value.
Generic class-validator options.
Checks if the given value is a Dayjs object not earlier than minimum
.
// Ensure the value is after the infamous Y2K.
@MinDayjs('2000-01-01T00:00:00.000Z')
y2kUnsafeDate: Dayjs
The minimum allowed value.
Generic class-validator options.
Checks if the given value is a Dayjs object in the past.
Beware that the behaviour of this check depends on the current time and can thus be difficult to test.
// Ensure the value is in the past.
@PastDayjs()
created: Dayjs
Generic class-validator options.
Checks if the given value is a Map and contains all required values.
// Ensure the map contains (at least) 'foo' and 'bar'.
@MapContains(['foo', 'bar'])
values: Map<number, string>
The type of values to check for.
The values required in the given map.
Generic class-validator options.
Checks if the given value is a Map and contains all required keys.
// Ensure the map contains (at least) the keys 13 and 42.
@MapContainsKeys([13, 42])
values: Map<number, string>
The type of keys to check for.
The keys required in the given map.
Generic class-validator options.
Checks if the given value is a Map
with no more than maximum
entries.
// Ensure the map has at most 5 entries.
@MapMaxSize(5)
values: Map<string, string>
The maximum allowed size of the map.
Generic class-validator options.
Checks if the given value is a Map
with no fewer than minimum
entries.
// Ensure the map has at least 5 entries.
@MapMinSize(5)
values: Map<string, string>
The minimum allowed size of the map.
Generic class-validator options.
Checks if the given value is a Map which does not contain any of the forbidden values.
// Ensure the map contains does not include the values 'foo' and 'bar'.
@MapNotContains(['foo', 'bar'])
values: Map<number, string>
The type of values to check for.
The values forbidden in the given map.
Generic class-validator options.
Checks if the given value is a Map which does not contain any of the forbidden keys.
// Ensure the map contains does not include the keys 13 and 42.
@MapNotContainsKeys(13, 42)
values: Map<number, string>
The type of keys to check for.
The values forbidden in the given map.
Generic class-validator options.
Checks if the given value is a Map without duplicates with regard to the given projection.
// Ensure the map does not include duplicate users.
@MapUnique<User>(user => user.id)
usersByEmail: Map<string, User>
The type of the map's values.
The type returned by projection
.
The function mapping each map entry to the value that is used for the uniqueness check.
Generic class-validator options.
Checks if the given value is a Map whose keys are all unique with regard to the given projection.
// Ensure there are no duplicate user ids in the map.
@MapUniqueKeys<User>(user => user.id)
postsByUser: Map<User, Post[]>
The type of the map's keys.
The type returned by projection
.
The function mapping each key to the value that is used for the uniqueness check.
Generic class-validator options.
Checks if the given value is a Set and contains all required values.
// Ensure the set contains (at least) 'foo' and 'bar'.
@SetContains(['foo', 'bar'])
values: Set<string>
The type of values to check for.
The values required in the given set.
Generic class-validator options.
Checks if the given value is a Set
with no more than maximum
values.
// Ensure the set has at most 5 entries.
@SetMaxSize(5)
values: Set<string>
The maximum allowed size of the set.
Generic class-validator options.
Checks if the given value is a Set
with no fewer than minimum
values.
// Ensure the set has at least 5 entries.
@SetMinSize(5)
values: Set<string>
The minimum allowed size of the set.
Generic class-validator options.
Checks if the given value is a Set which does not contain any of the forbidden values.
// Ensure the set contains does not include the values 'foo' and 'bar'.
@SetNotContains(['foo', 'bar'])
values: Set<string>
The type of values to check for.
The values forbidden in the given set.
Generic class-validator options.
Checks if the given value is a Set without duplicate values with regard to the given projection.
// Ensure the set does not include duplicate users.
@SetUnique<User>(user => user.id)
administrators: Set<User>
The type of the set's values.
The type returned by projection
.
The function mapping each value to the value that is used for the uniqueness check.
Generic class-validator options.
Checks if the given value is an AWS ARN string (as specified in the AWS Documentation).
Beware that this decorator only checks for syntactic validity, it does not check if the partition, service or region really exists. The region and account id are always optional, even if required for the specific service.
For example, the following strings are considered valid if though they are technically not:
arn:aws:foo:eu-central-1:bar
(there is no foo
AWS service)arn:aws:ec2::123456789012:instance/i-1234567890abcdef0
(EC2 requires a region which is omitted)arn:aws:ec2:us-east-42:123456789012:instance/i-1234567890abcdef0
(th region us-east-42
does not exist)// Ensure the value is a valid looking AWS ARN string
@IsAwsARN()
arn: string = 'arn:aws:clouddirectory:us-west-2:123456789012:schema/development/cognito'
Generic class-validator options.
Checks if the given value is an AWS region string.
Beware that this decorator only checks for syntactic validity, it does not check if the region really exists. For instance, it will accept "eu-central-9" which - at the time of writing - does not exist.
// Ensure the value is a valid looking AWS region
@IsAwsRegion()
region: string = 'eu-central-1'
Generic class-validator options.
Checks if the given value is a valid timezone string.
Generic class-validator options.
The type of the array elements.
The value to validate.
Additional options (see ArrayMonotonic).
The value to validate.
The value to validate.
The value to validate.
The value to validate.
The value to validate.
The value to validate.
Additional options (see IsDayjs).
The value to validate.
The value to validate.
The value to validate.
The value to validate.
The type of values to check for.
The value to validate.
List of mandatory values for this map.
The type of keys to check for.
The value to validate.
List of mandatory keys for this set.
The value to validate.
The maximum size of the set that is allowed.
The value to validate.
The minimum size of the map that is allowed.
The type of values to check for.
The value to validate.
List of forbidden values for this map.
The type of keys to check for.
The value to validate.
List of forbidden key values for this map.
The value to validate.
The type of the map's values.
The type returned by projection
.
The value to validate.
The function mapping each value to the value that is used for the uniqueness check.
The type of the map's keys.
The type returned by projection
.
The value to validate.
The function mapping each key to the value that is used for the uniqueness check.
The value to validate.
The maximum allowed value.
The value to validate.
The maximum allowed value.
The value to validate.
The minimum allowed value.
The value to validate.
The minimum allowed value.
The value to validate.
The value to validate.
The value to validate.
The value to validate.
The type of values to check for.
The value to validate.
List of mandatory values for this set.
The value to validate.
The maximum size of the set that is allowed.
The value to validate.
The minimum size of the set that is allowed.
The type of values to check for.
The value to validate.
List of forbidden values for this set.
The value to validate.
The type of the set's values.
The type returned by projection
.
The value to validate.
The function mapping each value to the value that is used for the uniqueness check.
The type of the map's keys.
The type returned by projection
.
Generated using TypeDoc
Checks if the given value is a BigInt.
Example