Skip to content
Open
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
10 changes: 5 additions & 5 deletions src/decorator/string/IsIBAN.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { ValidationOptions } from '../ValidationOptions';
import { buildMessage, ValidateBy } from '../common/ValidateBy';
import isIBANValidator from 'validator/lib/isIBAN';
import isIBANValidator, { IsIBANOptions } from 'validator/lib/isIBAN';

export const IS_IBAN = 'isIBAN';

/**
* Check if a string is a IBAN (International Bank Account Number).
* If given value is not a string, then it returns false.
*/
export function isIBAN(value: unknown): boolean {
return typeof value === 'string' && isIBANValidator(value);
export function isIBAN(value: unknown, options?: IsIBANOptions): boolean {
return typeof value === 'string' && isIBANValidator(value, options);
}

/**
* Check if a string is a IBAN (International Bank Account Number).
* If given value is not a string, then it returns false.
*/
export function IsIBAN(validationOptions?: ValidationOptions): PropertyDecorator {
export function IsIBAN(options?: IsIBANOptions, validationOptions?: ValidationOptions): PropertyDecorator {
return ValidateBy(
{
name: IS_IBAN,
validator: {
validate: (value, args): boolean => isIBAN(value),
validate: (value, args): boolean => isIBAN(value, options),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be an IBAN', validationOptions),
},
},
Expand Down