Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/decorator/array/ArrayContains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function ArrayContains(values: any[], validationOptions?: ValidationOptio
name: ARRAY_CONTAINS,
constraints: [values],
validator: {
validate: (value, args): boolean => arrayContains(value, args.constraints[0]),
validate: (value, args): boolean => arrayContains(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must contain $constraint1 values',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/array/ArrayMaxSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function ArrayMaxSize(max: number, validationOptions?: ValidationOptions)
name: ARRAY_MAX_SIZE,
constraints: [max],
validator: {
validate: (value, args): boolean => arrayMaxSize(value, args.constraints[0]),
validate: (value, args): boolean => arrayMaxSize(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must contain not more than $constraint1 elements',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/array/ArrayMinSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function ArrayMinSize(min: number, validationOptions?: ValidationOptions)
name: ARRAY_MIN_SIZE,
constraints: [min],
validator: {
validate: (value, args): boolean => arrayMinSize(value, args.constraints[0]),
validate: (value, args): boolean => arrayMinSize(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must contain at least $constraint1 elements',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/array/ArrayNotContains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function ArrayNotContains(values: any[], validationOptions?: ValidationOp
name: ARRAY_NOT_CONTAINS,
constraints: [values],
validator: {
validate: (value, args): boolean => arrayNotContains(value, args.constraints[0]),
validate: (value, args): boolean => arrayNotContains(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property should not contain $constraint1 values',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/common/Equals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function Equals(comparison: any, validationOptions?: ValidationOptions):
name: EQUALS,
constraints: [comparison],
validator: {
validate: (value, args): boolean => equals(value, args.constraints[0]),
validate: (value, args): boolean => equals(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must be equal to $constraint1',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/common/IsIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function IsIn(values: readonly any[], validationOptions?: ValidationOptio
name: IS_IN,
constraints: [values],
validator: {
validate: (value, args): boolean => isIn(value, args.constraints[0]),
validate: (value, args): boolean => isIn(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must be one of the following values: $constraint1',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/common/IsNotIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function IsNotIn(values: readonly any[], validationOptions?: ValidationOp
name: IS_NOT_IN,
constraints: [values],
validator: {
validate: (value, args): boolean => isNotIn(value, args.constraints[0]),
validate: (value, args): boolean => isNotIn(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property should not be one of the following values: $constraint1',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/common/NotEquals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function NotEquals(comparison: any, validationOptions?: ValidationOptions
name: NOT_EQUALS,
constraints: [comparison],
validator: {
validate: (value, args): boolean => notEquals(value, args.constraints[0]),
validate: (value, args): boolean => notEquals(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property should not be equal to $constraint1',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/date/MaxDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function MaxDate(date: Date, validationOptions?: ValidationOptions): Prop
name: MAX_DATE,
constraints: [date],
validator: {
validate: (value, args): boolean => maxDate(value, args.constraints[0]),
validate: (value, args): boolean => maxDate(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => 'maximal allowed date for ' + eachPrefix + '$property is $constraint1',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/date/MinDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function MinDate(date: Date, validationOptions?: ValidationOptions): Prop
name: MIN_DATE,
constraints: [date],
validator: {
validate: (value, args): boolean => minDate(value, args.constraints[0]),
validate: (value, args): boolean => minDate(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => 'minimal allowed date for ' + eachPrefix + '$property is $constraint1',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/number/IsDivisibleBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function IsDivisibleBy(num: number, validationOptions?: ValidationOptions
name: IS_DIVISIBLE_BY,
constraints: [num],
validator: {
validate: (value, args): boolean => isDivisibleBy(value, args.constraints[0]),
validate: (value, args): boolean => isDivisibleBy(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must be divisible by $constraint1',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/number/Max.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function Max(maxValue: number, validationOptions?: ValidationOptions): Pr
name: MAX,
constraints: [maxValue],
validator: {
validate: (value, args): boolean => max(value, args.constraints[0]),
validate: (value, args): boolean => max(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must not be greater than $constraint1',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/number/Min.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function Min(minValue: number, validationOptions?: ValidationOptions): Pr
name: MIN,
constraints: [minValue],
validator: {
validate: (value, args): boolean => min(value, args.constraints[0]),
validate: (value, args): boolean => min(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must not be less than $constraint1',
validationOptions
Expand Down
6 changes: 3 additions & 3 deletions src/decorator/object/IsInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export function IsInstance(
name: IS_INSTANCE,
constraints: [targetType],
validator: {
validate: (value, args): boolean => isInstance(value, args.constraints[0]),
validate: (value, args): boolean => isInstance(value, args?.constraints[0]),
defaultMessage: buildMessage((eachPrefix, args) => {
if (args.constraints[0]) {
return eachPrefix + `$property must be an instance of ${args.constraints[0].name as string}`;
if (args?.constraints[0]) {
return eachPrefix + `$property must be an instance of ${args?.constraints[0].name as string}`;
} else {
return eachPrefix + `${IS_INSTANCE} decorator expects and object as value, but got falsy value.`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/object/IsNotEmptyObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function IsNotEmptyObject(
name: IS_NOT_EMPTY_OBJECT,
constraints: [options],
validator: {
validate: (value, args): boolean => isNotEmptyObject(value, args.constraints[0]),
validate: (value, args): boolean => isNotEmptyObject(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must be a non-empty object',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/Contains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function Contains(seed: string, validationOptions?: ValidationOptions): P
name: CONTAINS,
constraints: [seed],
validator: {
validate: (value, args): boolean => contains(value, args.constraints[0]),
validate: (value, args): boolean => contains(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must contain a $constraint1 string',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsAlpha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function IsAlpha(locale?: string, validationOptions?: ValidationOptions):
name: IS_ALPHA,
constraints: [locale],
validator: {
validate: (value, args): boolean => isAlpha(value, args.constraints[0]),
validate: (value, args): boolean => isAlpha(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must contain only letters (a-zA-Z)',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsAlphanumeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function IsAlphanumeric(locale?: string, validationOptions?: ValidationOp
name: IS_ALPHANUMERIC,
constraints: [locale],
validator: {
validate: (value, args): boolean => isAlphanumeric(value, args.constraints[0]),
validate: (value, args): boolean => isAlphanumeric(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must contain only letters and numbers',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsByteLength.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function IsByteLength(min: number, max?: number, validationOptions?: Vali
name: IS_BYTE_LENGTH,
constraints: [min, max],
validator: {
validate: (value, args): boolean => isByteLength(value, args.constraints[0], args.constraints[1]),
validate: (value, args): boolean => isByteLength(value, args?.constraints[0], args?.constraints[1]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + "$property's byte length must fall into ($constraint1, $constraint2) range",
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsCurrency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function IsCurrency(
name: IS_CURRENCY,
constraints: [options],
validator: {
validate: (value, args): boolean => isCurrency(value, args.constraints[0]),
validate: (value, args): boolean => isCurrency(value, args?.constraints[0]),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be a currency', validationOptions),
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsDecimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function IsDecimal(
name: IS_DECIMAL,
constraints: [options],
validator: {
validate: (value, args): boolean => isDecimal(value, args.constraints[0]),
validate: (value, args): boolean => isDecimal(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property is not a valid decimal number.',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function IsEmail(
name: IS_EMAIL,
constraints: [options],
validator: {
validate: (value, args): boolean => isEmail(value, args.constraints[0]),
validate: (value, args): boolean => isEmail(value, args?.constraints[0]),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be an email', validationOptions),
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsFQDN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function IsFQDN(options?: ValidatorJS.IsFQDNOptions, validationOptions?:
name: IS_FQDN,
constraints: [options],
validator: {
validate: (value, args): boolean => isFQDN(value, args.constraints[0]),
validate: (value, args): boolean => isFQDN(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must be a valid domain name',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function IsHash(algorithm: string, validationOptions?: ValidationOptions)
name: IS_HASH,
constraints: [algorithm],
validator: {
validate: (value, args): boolean => isHash(value, args.constraints[0]),
validate: (value, args): boolean => isHash(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must be a hash of type $constraint1',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsIP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function IsIP(version?: IsIpVersion, validationOptions?: ValidationOption
name: IS_IP,
constraints: [version],
validator: {
validate: (value, args): boolean => isIP(value, args.constraints[0]),
validate: (value, args): boolean => isIP(value, args?.constraints[0]),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be an ip address', validationOptions),
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsISBN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function IsISBN(version?: IsISBNVersion, validationOptions?: ValidationOp
name: IS_ISBN,
constraints: [version],
validator: {
validate: (value, args): boolean => isISBN(value, args.constraints[0]),
validate: (value, args): boolean => isISBN(value, args?.constraints[0]),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be an ISBN', validationOptions),
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsISO8601.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function IsISO8601(
name: IS_ISO8601,
constraints: [options],
validator: {
validate: (value, args): boolean => isISO8601(value, args.constraints[0]),
validate: (value, args): boolean => isISO8601(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must be a valid ISO 8601 date string',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsISSN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function IsISSN(options?: ValidatorJS.IsISSNOptions, validationOptions?:
name: IS_ISSN,
constraints: [options],
validator: {
validate: (value, args): boolean => isISSN(value, args.constraints[0]),
validate: (value, args): boolean => isISSN(value, args?.constraints[0]),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be a ISSN', validationOptions),
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsIdentityCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function IsIdentityCard(
name: IS_IDENTITY_CARD,
constraints: [locale],
validator: {
validate: (value, args): boolean => isIdentityCard(value, args.constraints[0]),
validate: (value, args): boolean => isIdentityCard(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must be a identity card number',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsMobilePhone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function IsMobilePhone(
name: IS_MOBILE_PHONE,
constraints: [locale, options],
validator: {
validate: (value, args): boolean => isMobilePhone(value, args.constraints[0], args.constraints[1]),
validate: (value, args): boolean => isMobilePhone(value, args?.constraints[0], args?.constraints[1]),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be a phone number', validationOptions),
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsNumberString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function IsNumberString(
name: IS_NUMBER_STRING,
constraints: [options],
validator: {
validate: (value, args): boolean => isNumberString(value, args.constraints[0]),
validate: (value, args): boolean => isNumberString(value, args?.constraints[0]),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be a number string', validationOptions),
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsPassportNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function IsPassportNumber(countryCode: string, validationOptions?: Valida
name: IS_PASSPORT_NUMBER,
constraints: [countryCode],
validator: {
validate: (value, args): boolean => isPassportNumber(value, args.constraints[0]),
validate: (value, args): boolean => isPassportNumber(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must be valid passport number',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsPhoneNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function IsPhoneNumber(region?: CountryCode, validationOptions?: Validati
name: IS_PHONE_NUMBER,
constraints: [region],
validator: {
validate: (value, args): boolean => isPhoneNumber(value, args.constraints[0]),
validate: (value, args): boolean => isPhoneNumber(value, args?.constraints[0]),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must be a valid phone number',
validationOptions
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsPostalCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function IsPostalCode(
name: IS_POSTAL_CODE,
constraints: [locale],
validator: {
validate: (value, args): boolean => isPostalCode(value, args.constraints[0]),
validate: (value, args): boolean => isPostalCode(value, args?.constraints[0]),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be a postal code', validationOptions),
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsRgbColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function IsRgbColor(includePercentValues?: boolean, validationOptions?: V
name: IS_RGB_COLOR,
constraints: [includePercentValues],
validator: {
validate: (value, args): boolean => isRgbColor(value, args.constraints[0]),
validate: (value, args): boolean => isRgbColor(value, args?.constraints[0]),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be RGB color', validationOptions),
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsUUID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function IsUUID(version?: UUIDVersion, validationOptions?: ValidationOpti
name: IS_UUID,
constraints: [version],
validator: {
validate: (value, args): boolean => isUUID(value, args.constraints[0]),
validate: (value, args): boolean => isUUID(value, args?.constraints[0]),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be a UUID', validationOptions),
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/IsUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function IsUrl(options?: ValidatorJS.IsURLOptions, validationOptions?: Va
name: IS_URL,
constraints: [options],
validator: {
validate: (value, args): boolean => isURL(value, args.constraints[0]),
validate: (value, args): boolean => isURL(value, args?.constraints[0]),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be an URL address', validationOptions),
},
},
Expand Down
10 changes: 5 additions & 5 deletions src/decorator/string/Length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export function Length(min: number, max?: number, validationOptions?: Validation
name: IS_LENGTH,
constraints: [min, max],
validator: {
validate: (value, args): boolean => length(value, args.constraints[0], args.constraints[1]),
validate: (value, args): boolean => length(value, args?.constraints[0], args?.constraints[1]),
defaultMessage: buildMessage((eachPrefix, args) => {
const isMinLength = args.constraints[0] !== null && args.constraints[0] !== undefined;
const isMaxLength = args.constraints[1] !== null && args.constraints[1] !== undefined;
if (isMinLength && (!args.value || args.value.length < args.constraints[0])) {
const isMinLength = args?.constraints[0] !== null && args?.constraints[0] !== undefined;
const isMaxLength = args?.constraints[1] !== null && args?.constraints[1] !== undefined;
if (isMinLength && (!args.value || args.value.length < args?.constraints[0])) {
return eachPrefix + '$property must be longer than or equal to $constraint1 characters';
} else if (isMaxLength && args.value.length > args.constraints[1]) {
} else if (isMaxLength && args.value.length > args?.constraints[1]) {
return eachPrefix + '$property must be shorter than or equal to $constraint2 characters';
}
return (
Expand Down
2 changes: 1 addition & 1 deletion src/decorator/string/Matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function Matches(
name: MATCHES,
constraints: [pattern, modifiers],
validator: {
validate: (value, args): boolean => matches(value, args.constraints[0], args.constraints[1]),
validate: (value, args): boolean => matches(value, args?.constraints[0], args?.constraints[1]),
defaultMessage: buildMessage(
(eachPrefix, args) => eachPrefix + '$property must match $constraint1 regular expression',
validationOptions
Expand Down
Loading