UNPKG

pigmentjs

Version:

A zero-dependency colour organisation, creation and manipulation library built for web developers.

28 lines 905 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatHex = exports.validateHex = exports.isValidHex = void 0; var isValidHex = function (hex) { return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(hex); }; exports.isValidHex = isValidHex; var validateHex = function (hex) { if (isValidHex(hex)) { return hex; } throw Error("Invalid hex string format."); }; exports.validateHex = validateHex; var formatHex = function (hex) { var fHex = hex[0] === "#" ? hex : "#".concat(hex); if (fHex.length === 7) { return fHex.toUpperCase(); } else if (fHex.length === 4) { return "#".concat(fHex[1]).concat(fHex[1]).concat(fHex[2]).concat(fHex[2]).concat(fHex[3]).concat(fHex[3]); } else { throw Error("Invalid hex string format."); } }; exports.formatHex = formatHex; //# sourceMappingURL=validations.js.map