File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ import { ValidationOptions } from '../ValidationOptions' ;
2+ import { buildMessage , ValidateBy } from '../common/ValidateBy' ;
3+ import isISO6391Validator from 'validator/lib/isISO6391' ;
4+
5+ export const IS_ISO6391 = 'isISO6391' ;
6+
7+ /**
8+ * Check if the string is a valid [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) officially assigned language code.
9+ */
10+ export function isISO6391 ( value : unknown ) : boolean {
11+ return typeof value === 'string' && isISO6391Validator ( value ) ;
12+ }
13+
14+ /**
15+ * Check if the string is a valid [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) officially assigned language code.
16+ */
17+ export function IsISO6391 ( validationOptions ?: ValidationOptions ) : PropertyDecorator {
18+ return ValidateBy (
19+ {
20+ name : IS_ISO6391 ,
21+ validator : {
22+ validate : ( value , args ) : boolean => isISO6391 ( value ) ,
23+ defaultMessage : buildMessage (
24+ eachPrefix => eachPrefix + '$property must be a valid ISO 639-1 language code' ,
25+ validationOptions
26+ ) ,
27+ } ,
28+ } ,
29+ validationOptions
30+ ) ;
31+ }
You can’t perform that action at this time.
0 commit comments