What is hsla-regex?
The hsla-regex npm package provides a regular expression for matching HSLA (Hue, Saturation, Lightness, Alpha) color strings. This can be useful for validating, parsing, or extracting HSLA color values from strings.
What are hsla-regex's main functionalities?
Match HSLA color strings
This feature allows you to match HSLA color strings within a larger string. The code sample demonstrates how to use the hsla-regex package to find an HSLA color string in a CSS declaration.
const hslaRegex = require('hsla-regex');
const str = 'background-color: hsla(120, 100%, 50%, 0.3);';
const match = str.match(hslaRegex());
console.log(match); // ['hsla(120, 100%, 50%, 0.3)']
Validate HSLA color strings
This feature allows you to validate whether a given string is a valid HSLA color string. The code sample shows how to use the hsla-regex package to check if a string is a valid HSLA color.
const hslaRegex = require('hsla-regex');
const isValidHsla = (str) => hslaRegex().test(str);
console.log(isValidHsla('hsla(120, 100%, 50%, 0.3)')); // true
console.log(isValidHsla('rgb(255, 0, 0)')); // false
Other packages similar to hsla-regex
color-string
The color-string package provides functions for parsing and generating color strings in various formats, including HSLA. It offers more comprehensive functionality compared to hsla-regex, as it supports multiple color formats (RGB, HSL, HEX, etc.) and can convert between them.
css-color-function
The css-color-function package allows you to parse and manipulate CSS color functions, including HSLA. It provides more advanced features for color manipulation and conversion, making it a more powerful tool for working with CSS colors compared to hsla-regex.
color
The color package is a comprehensive library for color conversion and manipulation. It supports a wide range of color formats, including HSLA, and provides methods for color transformations, making it a more versatile option compared to hsla-regex.
hsla-regex
Regex for matching HSLA colors.
Installation
npm install --save hsla-regex
Usage
var hslaRegex = require('hsla-regex');
hslaRegex({ exact: true }).test('hsla(123, 45%, 67%, .8)');
hslaRegex({ exact: true }).test('foo bar');
hslaRegex({ exact: true }).exec('hsla(1, 1.111%, 1.1111%, .8)');
'hsla(123, 45%, 67%, .8) cats and dogs'.match(hslaRegex());
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.