What is hsl-regex?
The hsl-regex package provides a regular expression specifically designed to match HSL (Hue, Saturation, Lightness) color codes in strings. This can be particularly useful for validating and extracting HSL color values from text content in web development and software projects that deal with color data.
What are hsl-regex's main functionalities?
HSL Color Matching
This feature allows you to match HSL color values within a string. The provided code sample demonstrates how to use the hsl-regex package to find HSL values in a CSS style declaration.
const hslRegex = require('hsl-regex');
const text = 'background-color: hsl(210, 50%, 50%);';
const matches = text.match(hslRegex());
console.log(matches);
Other packages similar to hsl-regex
color-regex
Similar to hsl-regex, color-regex offers regex patterns for matching various color formats, including HSL. It provides a broader scope by supporting not only HSL but also HEX, RGB, and other color models. This makes color-regex more versatile if you need support for multiple color formats.
rgb-regex
While rgb-regex is focused on matching RGB color formats, it serves a similar purpose to hsl-regex by providing regex patterns for color values. It is less suitable if you specifically need to match HSL colors but is ideal for projects that predominantly deal with RGB color data.
hsl-regex

Regex for matching HSL colors.
Installation
npm install --save hsl-regex
Usage
var hslRegex = require('hsl-regex');
hslRegex({ exact: true }).test('hsl(123, 45%, 67%)');
hslRegex({ exact: true }).test('foo bar');
hslRegex({ exact: true }).exec('hsl(1, 1.111%, 1.1111%)');
'hsl(123, 45%, 67%) cats and dogs'.match(hslRegex());
License
MIT
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
)
- Commit your changes (
git commit -am 'Add some feature'
)
- Push to the branch (
git push origin my-new-feature
)
- Create new Pull Request
Crafted with <3 by John Otander (@4lpine).
This package was initially generated with yeoman and the p generator.