Skip to content
Closed
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ isBoolean(value);
| `@IsBase32()` | Checks if a string is base32 encoded. |
| `@IsBase58()` | Checks if a string is base58 encoded. |
| `@IsBase64(options?: IsBase64Options)` | Checks if a string is base64 encoded. |
| `@IsIBAN()` | Checks if a string is a IBAN (International Bank Account Number). |
| `@IsIBAN(options?: IsIBANOptions)` | Checks if a string is a IBAN (International Bank Account Number). |
| `@IsBIC()` | Checks if a string is a BIC (Bank Identification Code) or SWIFT code. |
| `@IsByteLength(min: number, max?: number)` | Checks if the string's length (in bytes) falls in a range. |
| `@IsCreditCard()` | Checks if the string is a credit card. |
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"test:ci": "jest --runInBand --no-cache --coverage --verbose"
},
"dependencies": {
"@types/validator": "^13.9.0",
"@types/validator": "^13.11.1",
"libphonenumber-js": "^1.10.39",
"validator": "^13.9.0"
"validator": "^13.11.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.3",
Expand Down
10 changes: 6 additions & 4 deletions src/decorator/string/IsIBAN.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import { ValidationOptions } from '../ValidationOptions';
import { buildMessage, ValidateBy } from '../common/ValidateBy';
import isIBANValidator from 'validator/lib/isIBAN';
import { 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,
constraints: [options],
validator: {
validate: (value, args): boolean => isIBAN(value),
validate: (value, args): boolean => isIBAN(value, args?.constraints[0]),
defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be an IBAN', validationOptions),
},
},
Expand Down