UNPKG

color-fns

Version:

Modern JavaScript color utility library.

63 lines 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function getCartesianCoords(r, theta) { return { x: r * Math.cos(theta * Math.PI * 2), y: r * Math.sin(theta * Math.PI * 2) }; } exports.getCartesianCoords = getCartesianCoords; function isBetween(lb, ub) { return function (value) { return value >= lb && value <= ub; }; } exports.isBetween = isBetween; ; function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } exports.getRandomInt = getRandomInt; function mixValue(val1, val2, ratio) { if (ratio === void 0) { ratio = 0.5; } return Number((val1 * (1 - ratio) + val2 * ratio).toFixed(2)); } exports.mixValue = mixValue; function isValidAlpha(alpha) { if (typeof alpha === 'number' && alpha >= 0 && alpha <= 1) { return true; } return false; } exports.isValidAlpha = isValidAlpha; /** * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc#Polyfill */ function truncateNum(num) { num = +num; if (!isFinite(num)) { return num; } return (num - num % 1) || (num < 0 ? -0 : num === 0 ? num : 0); } exports.truncateNum = truncateNum; function decNumToHex(decNum) { decNum = Math.floor(decNum); if (isNaN(decNum)) { return '00'; } return ('0' + decNum.toString(16)).slice(-2); } exports.decNumToHex = decNumToHex; function hexNumToDec(hexNum) { if (isNaN(parseInt(hexNum, 16))) { return 0; } return parseInt(hexNum, 16); } exports.hexNumToDec = hexNumToDec; function normalizeDecNum(value) { return Math.min(Math.max(truncateNum(value), 0), 255); } exports.normalizeDecNum = normalizeDecNum; //# sourceMappingURL=utils.js.map