JSPM

css-color-converter

1.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 54600
  • Score
    100M100P100Q151790F
  • License MIT

Converts CSS colors from one representation to another

Package Exports

  • css-color-converter

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (css-color-converter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

css-color-converter Build Status

Converts CSS colors from one representation to another

Installation

npm install css-color-converter

Usage

var color = require('css-color-converter');

color('rgb(255, 255, 255)').toHslString(); // hsl(0, 0%, 100%)
color('rgba(255, 255, 255, 0.5)').toHslString(); // hsla(0, 0%, 100%, 0.5)
color('blue').toRgbString(); // rgb(0, 0, 255)
color('red').toHexString(); // #ff0000

Methods

fromRgb([r, g, b])

parameter type description
r int red (0-255)
g int green (0-255)
b int blue (0-255)

Returns instance

fromRgba([r, g, b, a])

parameter type description
r int red (0-255)
g int green (0-255)
b int blue (0-255)
a float alpha (0-1)

Returns instance

fromHsl([h, s, l])

parameter type description
h int hue (0-360)
s int saturation (0-100)
l int luminosity (0-100)

Returns instance

fromHsla([h, s, l, a])

parameter type description
h int hue (0-360)
s int saturation (0-100)
l int luminosity (0-100)
a float alpha (0-1)

Returns instance

toRgbString()

Returns rgb() or rgba(), depending on the alpha.

toHslString()

Returns hsl() or hsla(), depending on the alpha.

toHexString()

Returns 6-digit or 8-digit hex, depending on the alpha.

toRgbaArray()

Returns [r, g, b, a] array.