npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@asamuzakjp/css-color

v1.1.0

Published

CSS color - Resolve, parse, convert CSS color.

Downloads

233

Readme

CSS color

build CodeQL npm (scoped)

Resolve, parse, convert CSS color.

Install

npm i @asamuzakjp/css-color

Usage

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

const rgb = resolve('color-mix(in srgb, red, blue)');
// 'rgb(128, 0, 128)'

const xyz = parse('lab(46.2775% -47.5621 48.5837)');
const hex = convert.xyzToHex(xyz);
// '#008000'

resolve

Resolve CSS color.

Parameters

  • color string color value
  • opt object? options
    • opt.currentColor string? color to use for currentcolor keyword
    • opt.format string? output format, one of rgb(default), array, hex or hexAlpha
      • hexAlpha gets hex color with alpha channel, i.e. #rrggbbaa
    • opt.key any? key e.g. CSS property background-color

Returns (string? | Array) rgba?(), [r, g, b, a], #rrggbb(aa)?, null, or if key is specified, [key, rgba?()|[r, g, b, a]|#rrggbb(aa)?|null]

  • In rgb:
    • r, g, b values are rounded.
    • Returns empty string for unknown / unsupported color name.
  • In array:
    • Values are floats.
    • Returns array filled with undefined for unknown / unsupported color name, i.e. [undefined, undefined, undefined, undefined].
  • In hex:
    • transparent returns null.
    • Also returns null for unknown / unsupported color name.
    • currentcolor resolves as #000000 if opt.currentColor is not specified.
  • In hexAlpha:
    • transparent resolves as #00000000.
    • currentcolor resolves as #00000000 if opt.currentColor is not specified.
    • Returns null for unknown / unsupported color name.

parse

Parse CSS color.

Parameters

Returns Array<number> [x, y, z, a] x|y|z|a: 0..1

convert

Contains various conversion functions as properties.

convert.numberToHex

Convert number to hex string.

Parameters

Returns string hex string 00..ff

convert.hexToRgb

Convert hex color to rgb color array.

Parameters

Returns Array<number> [r, g, b, a] r|g|b: 0..255 a: 0..1

convert.rgbToHex

Convert rgb to hex color notation.

Parameters

Returns string #rrggbbaa

convert.xyzToHex

Convert xyz to hex color notation.

Parameters

Returns string #rrggbbaa

convert.xyzToHsl

Convert xyz to hsl color array.

Parameters

Returns Array<number> [h, s, l, a] h: 0..360 s|l: 0..100 a: 0..1

convert.xyzToHwb

Convert xyz to hwb color array.

Parameters

Returns Array<number> [h, w, b, a] h: 0..360 w|b: 0..100 a: 0..1

convert.xyzToOklab

Convert xyz to oklab color array.

Parameters

Returns Array<number> [l, a, b, A] l|A: 0..1 a|b: -0.4..0.4

convert.xyzToOklch

Convert xyz to oklch color array.

Parameters

Returns Array<number> [l, c, h, a] l|a: 0..1 c: 0..0.4 h: 0..360

convert.xyzToRgb

Convert xyz to rgb color array.

Parameters

Returns Array<number> [r, g, b, a] r|g|b: 0..255 a: 0..1

convert.xyzToXyzD50

Convert xyz to xyz-d50 color array.

Parameters

Returns Array<number> xyz - [x, y, z, a] x|y|z|a: 0..1

convert.xyzD50ToLab

Convert xyz-d50 to lab color array.

Parameters

Returns Array<number> [l, a, b, A] l: 0..100 a|b: -125..125 A: 0..1

convert.xyzD50ToLch

Convert xyz-d50 to lch color array.

Parameters

Returns Array<number> [l, c, h, a] l: 0..100 c: 0..150 h: 0..360 a: 0..1


Copyright (c) 2024 asamuzaK (Kazz)