UNPKG

1.28 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.IsHexColor = exports.isHexColor = exports.IS_HEX_COLOR = void 0;
7const ValidateBy_1 = require("../common/ValidateBy");
8const isHexColor_1 = __importDefault(require("validator/lib/isHexColor"));
9exports.IS_HEX_COLOR = 'isHexColor';
10/**
11 * Checks if the string is a hexadecimal color.
12 * If given value is not a string, then it returns false.
13 */
14function isHexColor(value) {
15 return typeof value === 'string' && (0, isHexColor_1.default)(value);
16}
17exports.isHexColor = isHexColor;
18/**
19 * Checks if the string is a hexadecimal color.
20 * If given value is not a string, then it returns false.
21 */
22function IsHexColor(validationOptions) {
23 return (0, ValidateBy_1.ValidateBy)({
24 name: exports.IS_HEX_COLOR,
25 validator: {
26 validate: (value, args) => isHexColor(value),
27 defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be a hexadecimal color', validationOptions),
28 },
29 }, validationOptions);
30}
31exports.IsHexColor = IsHexColor;
32//# sourceMappingURL=IsHexColor.js.map
\No newline at end of file