Skip to content

Instantly share code, notes, and snippets.

@atelierbram
Created March 10, 2026 08:55
Show Gist options
  • Select an option

  • Save atelierbram/2351a1acfeaca6d5becc3bb61fa35ecd to your computer and use it in GitHub Desktop.

Select an option

Save atelierbram/2351a1acfeaca6d5becc3bb61fa35ecd to your computer and use it in GitHub Desktop.
How to convert a range of HSL color values to HEX in batch with color-convert and write to file

How to convert a range of HSL color values to HEX in batch with color-convert and write to file

First install color-convert

  npm install color-convert

Create 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment