Writing module code
Now, it's time to in actual implementation details.
In this recipe, we will write some code for our hsl-to-hex
module.
Getting ready
Let's ensure that we have a folder called hsl-to-hex
, with a package.json
file in it. The package.json
file should contain hsl-to-rgb-for-reals
as a dependency. If there isn't a node_modules
folder, we need to ensure that we run npm install
from the command line with the working directory set to the hsl-to-hex
directory.
To get started, let's create a file called index.js
in thehsl-to-hex
folder, then open it in our favorite text editor.
How to do it...
The first thing we'll want to do in our index.js
file is specify any dependencies we'll be using.
In our case, there's only one dependency:
var toRgb = require('hsl-to-rgb-for-reals')
Typically, all dependencies should be declared at the top of the file.
Now, let's define an API for our module we're taking hue, saturation, and luminosity values and outputting a CSS compatible hex string.
Hue is in...