Skip to content
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

feat: Added a ISO639-1 decorator #2047

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/decorator/decorators.ts
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
@@ -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
);
}