First install color-convert
npm install color-convertCreate a javaScript file (different require syntax for CommonJs: https://reflectoring.io/nodejs-modules-imports/ , this is Common JS)
const colorConvertModule = require('color-convert');
const convert = colorConvertModule.default;
const fs = require('fs');
function hslToHex(hslColors) {
return hslColors.map(color => {
return '#' + convert.hsl.hex(color[0], color[1], color[2]);
});
}
const hslColors = [
[351, 100, 5],
[351, 100, 10],
[351, 100, 15],
[351, 100, 20],
[351, 100, 25],
[351, 100, 30],
[351, 100, 35],
[351, 98, 40],
[351, 94, 45],
[351, 87, 50],
[351, 94, 55],
[351, 98, 60],
[351, 100, 65],
[351, 100, 70],
[351, 100, 75],
[351, 100, 80],
[351, 100, 85],
[351, 100, 90],
[351, 100, 95]
];
const hexColors = hslToHex(hslColors);
fs.writeFile('color-conversions/red_hex-colors.txt', hexColors.join('\n'), (err) => {
if (err) {
console.error(err);
} else {
console.log('Hex colors written to file successfully!');
}
});Execute from the commandline with:
node path-to-file/hsl-colors-to-be-converted.js