Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Parser and generator for CSS color strings

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 test fix for hsla when alpha is 0 March 06, 2014
Octocat-spinner-32 Jakefile.js
Octocat-spinner-32 README.md
Octocat-spinner-32 color-string.js
Octocat-spinner-32 component.json
Octocat-spinner-32 package.json
README.md

color-string

color-string is a library for parsing and generating CSS color strings.

parsing:

colorString.getRgb("#FFF")  // [255, 255, 255]
colorString.getRgb("blue")  // [0, 0, 255]

colorString.getRgba("rgba(200, 60, 60, 0.3)")    // [200, 60, 60, 0.3]
colorString.getRgba("rgb(200, 200, 200)")        // [200, 200, 200, 1]

colorString.getHsl("hsl(360, 100%, 50%)")        // [360, 100, 50]
colorString.getHsla("hsla(360, 60%, 50%, 0.4)")  // [360, 60, 50, 0.4]

colorString.getAlpha("rgba(200, 0, 12, 0.6)")    // 0.6

generating:

colorString.hexString([255, 255, 255])   // "#FFFFFF"
colorString.rgbString([255, 255, 255])   // "rgb(255, 255, 255)"
colorString.rgbString([0, 0, 255, 0.4])  // "rgba(0, 0, 255, 0.4)"
colorString.rgbString([0, 0, 255], 0.4)  // "rgba(0, 0, 255, 0.4)"
colorString.percentString([0, 0, 255])   // "rgb(0%, 0%, 100%)"
colorString.keyword([255, 255, 0])       // "yellow"
colorString.hslString([360, 100, 100])   // "hsl(360, 100%, 100%)"

Install

node

For node with npm:

npm install color-string

browser

Download the latest color-string.js. The colorString object is exported.

Something went wrong with that request. Please try again.