Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@asamuzakjp/css-color

Package Overview
Dependencies
Maintainers
0
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@asamuzakjp/css-color

CSS color - Resolve and convert CSS colors.

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
273K
increased by171515.72%
Maintainers
0
Weekly downloads
 
Created
Source

CSS color

build CodeQL npm (scoped)

Resolve and convert CSS colors.

Install

npm i @asamuzakjp/css-color

Usage

import { convert, resolve } from '@asamuzakjp/css-color';

const resolvedValue =
  resolve('color-mix(in oklab, rgb(255 0 0), color(srgb 0 0.5 0 / 0.5))');
// 'oklab(0.5914 0.103273 0.119688 / 0.75)'

const convertedValue = covert.colorToHex('lab(46.2775% -47.5621 48.5837)');
// '#008000'

resolve(color, opt)

resolves CSS color

Parameters
  • color string color value

    • system colors are not supported
  • opt object? options (optional, default {})

    • opt.currentColor string? color to use for currentcolor keyword
    • opt.format string? output format, one of spec (default), rgb, hex, hexAlpha
      • hexAlpha is a hex color notation with alpha channel, i.e. #rrggbbaa
    • opt.key any? key e.g. CSS property background-color

Returns (string? | Array) returns one of rgba?(), color(space r g b / a), color(space x y z / a), lab(l a b / A), lch(l c h / a), oklab(l a b / A), oklch(l c h / a), \#rrggbb(aa)?, null, and, if key is specified, [key, rgba?()] etc.

  • in spec, values are numbers, however rgb() values are integers
  • in rgb, values are rounded to integers, and returns rgba(0, 0, 0, 0) for unknown colors
  • in hex, transparent value is resolved as null, also returns null if any of r, g, b, a is not a number
  • in hexAlpha, transparent resolves as #00000000, and returns null if any of r, g, b, a is not a number

convert

Contains various conversion functions as properties.

numberToHex(value)

convert number to hex string

Parameters

Returns string hex string: 00..ff

colorToHex(value, opt)

convert color to hex

Parameters
  • value string color value
  • opt object? options (optional, default {})
    • opt.alpha boolean? return in #rrggbbaa notation

Returns string #rrggbb|#rrggbbaa

colorToHsl(value)

convert color to hsl

Parameters

Returns Array<number> [h, s, l, a]

colorToHwb(value)

convert color to hwb

Parameters

Returns Array<number> [h, w, b, a]

colorToLab(value)

convert color to lab

Parameters

Returns Array<number> [l, a, b, aa]

colorToLch(value)

convert color to lch

Parameters

Returns Array<number> [l, c, h, aa]

colorToOklab(value)

convert color to oklab

Parameters

Returns Array<number> [l, a, b, aa]

colorToOklch(value)

convert color to oklch

Parameters

Returns Array<number> [l, c, h, aa]

colorToRgb(value)

convert color to rgb

Parameters

Returns Array<number> [r, g, b, a]

colorToXyz(value, opt)

convert color to xyz

Parameters
  • value string color value
  • opt object? options (optional, default {})
    • opt.d50 boolean? xyz in d50 white point

Returns Array<number> [x, y, z, a]

colorToXyzD50(value)

convert color to xyz-d50

Parameters

Returns Array<number> [x, y, z, a]


Copyright (c) 2024 asamuzaK (Kazz)

FAQs

Package last updated on 30 Nov 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc