UNPKG

1.75 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.IsRgbColor = exports.isRgbColor = exports.IS_RGB_COLOR = void 0;
7const ValidateBy_1 = require("../common/ValidateBy");
8const isRgbColor_1 = __importDefault(require("validator/lib/isRgbColor"));
9exports.IS_RGB_COLOR = 'isRgbColor';
10/**
11 * Check if the string is a rgb or rgba color.
12 * `includePercentValues` defaults to true. If you don't want to allow to set rgb or rgba values with percents, like rgb(5%,5%,5%), or rgba(90%,90%,90%,.3), then set it to false.
13 * If given value is not a string, then it returns false.
14 */
15function isRgbColor(value, includePercentValues) {
16 return typeof value === 'string' && (0, isRgbColor_1.default)(value, includePercentValues);
17}
18exports.isRgbColor = isRgbColor;
19/**
20 * Check if the string is a rgb or rgba color.
21 * `includePercentValues` defaults to true. If you don't want to allow to set rgb or rgba values with percents, like rgb(5%,5%,5%), or rgba(90%,90%,90%,.3), then set it to false.
22 * If given value is not a string, then it returns false.
23 */
24function IsRgbColor(includePercentValues, validationOptions) {
25 return (0, ValidateBy_1.ValidateBy)({
26 name: exports.IS_RGB_COLOR,
27 constraints: [includePercentValues],
28 validator: {
29 validate: (value, args) => isRgbColor(value, args.constraints[0]),
30 defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be RGB color', validationOptions),
31 },
32 }, validationOptions);
33}
34exports.IsRgbColor = IsRgbColor;
35//# sourceMappingURL=IsRgbColor.js.map
\No newline at end of file