UNPKG

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