get-best-contrast-color calculates which color in an array of colors gives the highest contrast to another color.
Doesn't handle transparency as of yet.
$ npm install get-best-contrast-colorimport bestContrast from 'get-best-contrast-color';
const background1 = 'palevioletred';
const background2 = 'saddlebrown';
const colors = [
'#222',
'blue',
'rgb(255, 255, ,255)',
];
bestContrast(background1, colors); // '#222'
bestContrast(background2, colors); // 'rgb(255, 255, 255)'(background: string, colors: array) => string