UNPKG

828 BJavaScriptView Raw
1import { buildMessage, ValidateBy } from '../common/ValidateBy';
2import isLocaleValidator from 'validator/lib/isLocale';
3export const IS_LOCALE = 'isLocale';
4/**
5 * Check if the string is a locale.
6 * If given value is not a string, then it returns false.
7 */
8export function isLocale(value) {
9 return typeof value === 'string' && isLocaleValidator(value);
10}
11/**
12 * Check if the string is a locale.
13 * If given value is not a string, then it returns false.
14 */
15export function IsLocale(validationOptions) {
16 return ValidateBy({
17 name: IS_LOCALE,
18 validator: {
19 validate: (value, args) => isLocale(value),
20 defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be locale', validationOptions),
21 },
22 }, validationOptions);
23}
24//# sourceMappingURL=IsLocale.js.map
\No newline at end of file