UNPKG

@onesy/utils

Version:
21 lines (20 loc) 842 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const is_1 = __importDefault(require("./is")); const colorToRgb_1 = __importDefault(require("./colorToRgb")); const getLuminance = (value) => { let values = (0, colorToRgb_1.default)(value, undefined, true); if ((0, is_1.default)('array', values) && values.length >= 3) { values = values.slice(0, 3).map(item => { // Normalize item /= 255; return item <= 0.03928 ? item / 12.92 : ((item + 0.055) / 1.055) ** 2.4; }); const [r, g, b] = values; return Number((r * 0.2126 + g * 0.7152 + b * 0.0722).toFixed(2)); } }; exports.default = getLuminance;