Skip to content

feat(IsIBAN): Add IsIBANOptions as argument for IsIBAN decorator #2618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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