Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/decorator/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export * from './string/IsIP';
export * from './string/IsPort';
export * from './string/IsISBN';
export * from './string/IsISIN';
export * from './string/IsISO6391';
export * from './string/IsISO8601';
export * from './string/IsJSON';
export * from './string/IsJWT';
Expand Down
33 changes: 33 additions & 0 deletions src/decorator/string/IsISO6391.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ValidationOptions } from '../ValidationOptions';
import { buildMessage, ValidateBy } from '../common/ValidateBy';
import isISO6391 from 'validator/lib/isISO6391';

export const IS_ISO6391 = 'isISO6391';

/**
* Checks if the string is an ISO 639-1 (the country language code).
* If given value is not a string, then it returns false.
*/
export function isIso6391(value: unknown): boolean {
return typeof value === 'string' && isISO6391(value);
}

/**
* Checks if the string is an ISIN (stock/security identifier).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy/paste error from other decorator.

* If given value is not a string, then it returns false.
*/
export function IsISO6391(validationOptions?: ValidationOptions): PropertyDecorator {
return ValidateBy(
{
name: IS_ISO6391,
validator: {
validate: (value, args): boolean => isIso6391(value),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must be an ISO 639-1 (the country language code)',
validationOptions
),
},
},
validationOptions
);
}