@chayns/colors
Version:
JavaScript utility functions for the calculation of colors for chayns
52 lines (51 loc) • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isHex = isHex;
exports.isHsl = isHsl;
exports.isHsv = isHsv;
exports.isInInterval = isInInterval;
exports.isNullOrUndefined = isNullOrUndefined;
exports.isNumber = isNumber;
exports.isObject = isObject;
exports.isRgb1 = isRgb1;
exports.isRgb255 = isRgb255;
exports.isRgbString = isRgbString;
exports.isString = isString;
var _constants = require("./constants");
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function isString(value) {
return typeof value === 'string';
}
function isNumber(value) {
return typeof value === 'number' && !Number.isNaN(value);
}
function isNullOrUndefined(value) {
return value === undefined || value === null || Number.isNaN(value);
}
function isObject(value) {
return _typeof(value) === 'object' && value !== null;
}
function isInInterval(value, min, max) {
return isNumber(value) && value >= min && value <= max;
}
function isHex(value) {
return _constants.HEX_REGEX.test(value);
}
function isRgbString(value) {
return _constants.RGB_REGEX.test(value);
}
function isRgb255(value) {
return isObject(value) && isInInterval(value.r, 0, 255) && isInInterval(value.g, 0, 255) && isInInterval(value.b, 0, 255) && (isNullOrUndefined(value.a) || isInInterval(value.a, 0, 1));
}
function isRgb1(value) {
return isObject(value) && isInInterval(value.r, 0, 1) && isInInterval(value.g, 0, 1) && isInInterval(value.b, 0, 1) && (isNullOrUndefined(value.a) || isInInterval(value.a, 0, 1));
}
function isHsl(value) {
return isObject(value) && isInInterval(value.h, 0, 360) && isInInterval(value.s, 0, 1) && isInInterval(value.l, 0, 1) && (isNullOrUndefined(value.a) || isInInterval(value.a, 0, 1));
}
function isHsv(value) {
return isObject(value) && isInInterval(value.h, 0, 360) && isInInterval(value.s, 0, 1) && isInInterval(value.v, 0, 1) && (isNullOrUndefined(value.a) || isInInterval(value.a, 0, 1));
}
//# sourceMappingURL=is.js.map