What is rgba-regex?
The rgba-regex npm package provides a regular expression for matching RGBA color strings. This can be useful for validating, parsing, or extracting RGBA color values from strings in various applications.
What are rgba-regex's main functionalities?
Match RGBA color strings
This feature allows you to match RGBA color strings within a larger string. The code sample demonstrates how to use the rgba-regex package to find an RGBA color string in a CSS declaration.
const rgbaRegex = require('rgba-regex');
const str = 'background-color: rgba(255, 99, 71, 0.5);';
const match = str.match(rgbaRegex());
console.log(match); // ['rgba(255, 99, 71, 0.5)']
Validate RGBA color strings
This feature allows you to validate whether a given string is a valid RGBA color string. The code sample shows how to use the rgba-regex package to check if a string is a valid RGBA color.
const rgbaRegex = require('rgba-regex');
const isValidRgba = rgbaRegex().test('rgba(255, 99, 71, 0.5)');
console.log(isValidRgba); // true
Other packages similar to rgba-regex
color-string
The color-string package provides utilities for parsing and generating color strings, including RGBA. It offers more comprehensive functionality compared to rgba-regex, such as converting between different color formats (e.g., RGB, HSL) and manipulating color values.
css-color-function
The css-color-function package allows you to transform CSS color functions, including RGBA. It provides more advanced features for color manipulation and transformation, making it more versatile than rgba-regex for complex color operations.
color
The color package is a comprehensive library for color conversion and manipulation. It supports a wide range of color formats, including RGBA, and provides methods for color transformations, blending, and more. It offers a broader set of features compared to rgba-regex.
rgba-regex
Regex for matching RGBA color strings.
Installation
npm install --save rgba-regex
Usage
var rgbaRegex = require('rgba-regex');
rgbaRegex({ exact: true }).test('rgba(12, 34, 56, .8)');
rgbaRegex({ exact: true }).test('unicorns');
rgbaRegex({ exact: true }).test('rgba(,,,)');
rgbaRegex().exec('rgba(12, 34, 56, .8)');
'rgba(12, 34, 56, .8) cats and dogs'.match(rgbaRegex());
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.