Socket
Socket
Sign inDemoInstall

@csstools/css-color-parser

Package Overview
Dependencies
4
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @csstools/css-color-parser

Parse CSS color values


Version published
Maintainers
3
Install size
225 kB
Created

Readme

Source

CSS Color Parser

npm version Build Status Discord

Usage

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());
}

Keywords

FAQs

Last updated on 31 Mar 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc