
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@csstools/css-color-parser
Advanced tools
@csstools/css-color-parser is an npm package designed to parse CSS color values. It can handle a variety of color formats including named colors, hex codes, RGB, RGBA, HSL, and HSLA. This package is useful for developers who need to manipulate or validate CSS color values in their JavaScript applications.
Parse Named Colors
This feature allows you to parse named CSS colors. The code sample demonstrates how to parse the named color 'red' and log the resulting color object.
const { parse } = require('@csstools/css-color-parser');
const color = parse('red');
console.log(color);
Parse Hex Colors
This feature allows you to parse hex color codes. The code sample demonstrates how to parse the hex color '#ff0000' and log the resulting color object.
const { parse } = require('@csstools/css-color-parser');
const color = parse('#ff0000');
console.log(color);
Parse RGB Colors
This feature allows you to parse RGB color values. The code sample demonstrates how to parse the RGB color 'rgb(255, 0, 0)' and log the resulting color object.
const { parse } = require('@csstools/css-color-parser');
const color = parse('rgb(255, 0, 0)');
console.log(color);
Parse RGBA Colors
This feature allows you to parse RGBA color values. The code sample demonstrates how to parse the RGBA color 'rgba(255, 0, 0, 0.5)' and log the resulting color object.
const { parse } = require('@csstools/css-color-parser');
const color = parse('rgba(255, 0, 0, 0.5)');
console.log(color);
Parse HSL Colors
This feature allows you to parse HSL color values. The code sample demonstrates how to parse the HSL color 'hsl(0, 100%, 50%)' and log the resulting color object.
const { parse } = require('@csstools/css-color-parser');
const color = parse('hsl(0, 100%, 50%)');
console.log(color);
Parse HSLA Colors
This feature allows you to parse HSLA color values. The code sample demonstrates how to parse the HSLA color 'hsla(0, 100%, 50%, 0.5)' and log the resulting color object.
const { parse } = require('@csstools/css-color-parser');
const color = parse('hsla(0, 100%, 50%, 0.5)');
console.log(color);
The 'color' package is a comprehensive library for color conversion and manipulation. It supports a wide range of color formats and provides methods for color transformations. Compared to @csstools/css-color-parser, 'color' offers more extensive functionality for color manipulation beyond just parsing.
The 'tinycolor2' package is a fast and lightweight color manipulation library. It supports parsing, conversion, and manipulation of various color formats. While @csstools/css-color-parser focuses on parsing, 'tinycolor2' provides additional methods for color adjustments and transformations.
The 'chroma-js' package is a powerful library for color conversions and color scales. It supports a wide range of color formats and provides advanced features for color manipulation and visualization. Compared to @csstools/css-color-parser, 'chroma-js' offers more advanced capabilities for working with color scales and gradients.
Add CSS Color Parser to your project:
npm install @csstools/css-color-parser @csstools/css-parser-algorithms @csstools/css-tokenizer --save-dev
import { color } from '@csstools/css-color-parser';
import { isFunctionNode, parseComponentValue } from '@csstools/css-parser-algorithms';
import { serializeRGB } from '@csstools/css-color-parser';
import { tokenize } from '@csstools/css-tokenizer';
// color() expects a parsed component value.
const hwbComponentValue = parseComponentValue(tokenize({ css: 'hwb(10deg 10% 20%)' }));
const colorData = color(hwbComponentValue);
if (colorData) {
console.log(colorData);
// serializeRGB() returns a component value.
const rgbComponentValue = serializeRGB(colorData);
console.log(rgbComponentValue.toString());
}
FAQs
Parse CSS color values
The npm package @csstools/css-color-parser receives a total of 3,374,355 weekly downloads. As such, @csstools/css-color-parser popularity was classified as popular.
We found that @csstools/css-color-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.