How to do it...

Our hsl-to-hex module can be implemented in two steps:

  1. Convert the hue degrees, saturation percentage, and luminosity percentage to corresponding red, green, and blue numbers between 0 and 255.
  2. Convert the RGB values to HEX.

Before we tear into writing an HSL to the RGB algorithm, we should check whether this problem has already been solved.

The easiest way to check is to head to http://npmjs.com and perform a search:

Oh, look! Somebody already solved this.

After some research, we decide that the hsl-to-rgb-for-reals module is the best fit.

Ensuring that we are in the hsl-to-hex folder, we can now install our dependency with the following:

npm install --save hsl-to-rgb-for-reals
The --save flag
In npm versions 1 to 4 the --save flag was always necessary to add the dependency to the package.json, ensuring that it could then be installed later using npm install in the same folder as (or child folder to) the package.json file. However, in npm version 5 and up, modules will be saved to the package.json file by default. Throughout this book we consistently use the --save flag, since it doesn't hurt to use it in npm version 5 and up, but is necessary in npm version 1 to 4. If we're using npm version 5 with default configuration settings, we can safely disregard the --save flag (but not the --save-dev flag).

Now let's take a look at the bottom of package.json:

tail package.json #linux/osx 
type package.json #windows

Tail output should give us this:

  "bugs": {
"url": "https://github.com/davidmarkclements/hsl-to-hex/issues"
},
"homepage": "https://github.com/davidmarkclements/hsl-to-hex#readme",
"description": "",
"dependencies": {
"hsl-to-rgb-for-reals": "^1.1.0"
}
}

We can see that the dependency we installed has been added to a dependencies object in the package.json file.