Skip to content

feat: Added a ISO639-1 decorator #2047

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 2 commits 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.
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: {

Check warning on line 23 in src/decorator/string/IsISO6391.ts

View check run for this annotation

Codecov / codecov/patch

src/decorator/string/IsISO6391.ts#L23

Added line #L23 was not covered by tests
validate: (value, args): boolean => isIso6391(value),
defaultMessage: buildMessage(
eachPrefix => eachPrefix + '$property must be an ISO 639-1 (the country language code)',
validationOptions

Check warning on line 27 in src/decorator/string/IsISO6391.ts

View check run for this annotation

Codecov / codecov/patch

src/decorator/string/IsISO6391.ts#L26-L27

Added lines #L26 - L27 were not covered by tests
),
},
},
validationOptions
);
}