-
Notifications
You must be signed in to change notification settings - Fork 0
/
hex.js
32 lines (27 loc) · 819 Bytes
/
hex.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Provides the core functionality wrapped in hex color string helpers.
*/
"use strict";
const { correctContrast, relativeLuminance } = require("./index");
const { stringHexToRGB, rgbToStringHex } = require("./lib/hexhelper");
/**
*
* @param {string} hex string color
* @param {number} backgroundLuminance
* @param {number} desiredContrast
* @returns {string} hex string color
*/
const correctContrastHex = (hex, backgroundLuminance, desiredContrast) =>
rgbToStringHex(
correctContrast(stringHexToRGB(hex), backgroundLuminance, desiredContrast)
);
/**
*
* @param {string} hex
* @returns {number} relative luminance
*/
const relativeLuminanceHex = hex => relativeLuminance(stringHexToRGB(hex));
module.exports = {
correctContrast: correctContrastHex,
relativeLuminance: relativeLuminanceHex
};