UNPKG

@akashshyam/color-utilities

Version:

A handy, tiny utility library compatible with typescript. We offer color conversions, color validation, constrast comparison etc

34 lines (33 loc) 954 B
"use strict"; /** * Validate if string is hexadecimal * @param hex string * @returns a boolean stating if the string is a valid hex */ Object.defineProperty(exports, "__esModule", { value: true }); exports.validateHSL = exports.validateRGB = exports.validateHex = void 0; function validateHex(hex) { var re = /^#[a-zA-Z0-9]{6}/; return re.test(hex); } exports.validateHex = validateHex; /** * Validate if string is rgb * @param rgb string * @returns a boolean stating if the string is a valid rgb */ function validateRGB(rgb) { var re = /rgb\(\"(\d{1,3}), (\d{1,3}), (\d{1,3})\"\)/; return re.test(rgb); } exports.validateRGB = validateRGB; /** * Validate if string is hsl * @param hsl string * @returns a boolean stating if the string is a valid hsl */ function validateHSL(hsl) { var re = /hsl\(\"\s*(\d+)\s*,\s*(\d+(?:\.\d+)?%)\s*,\s*(\d+(?:\.\d+)?%)\"\)/; return re.test(hsl); } exports.validateHSL = validateHSL;