1 | # color-string
|
2 | color-string is a library for parsing and generating CSS color strings.
|
3 |
|
4 | #### parsing:
|
5 | ```javascript
|
6 | colorString.getRgb("#FFF") // [255, 255, 255]
|
7 | colorString.getRgb("blue") // [0, 0, 255]
|
8 |
|
9 | colorString.getRgba("rgba(200, 60, 60, 0.3)") // [200, 60, 60, 0.3]
|
10 | colorString.getRgba("rgb(200, 200, 200)") // [200, 200, 200, 1]
|
11 |
|
12 | colorString.getHsl("hsl(360, 100%, 50%)") // [360, 100, 50]
|
13 | colorString.getHsla("hsla(360, 60%, 50%, 0.4)") // [360, 60, 50, 0.4]
|
14 |
|
15 | colorString.getAlpha("rgba(200, 0, 12, 0.6)") // 0.6
|
16 | ```
|
17 | #### generating:
|
18 | ```javascript
|
19 | colorString.hexString([255, 255, 255]) // "#FFFFFF"
|
20 | colorString.rgbString([255, 255, 255]) // "rgb(255, 255, 255)"
|
21 | colorString.rgbString([0, 0, 255, 0.4]) // "rgba(0, 0, 255, 0.4)"
|
22 | colorString.rgbString([0, 0, 255], 0.4) // "rgba(0, 0, 255, 0.4)"
|
23 | colorString.percentString([0, 0, 255]) // "rgb(0%, 0%, 100%)"
|
24 | colorString.keyword([255, 255, 0]) // "yellow"
|
25 | colorString.hslString([360, 100, 100]) // "hsl(360, 100%, 100%)"
|
26 | ```
|
27 |
|
28 | # Install
|
29 |
|
30 | ### node
|
31 | For [node](http://nodejs.org) with [npm](http://npmjs.org):
|
32 |
|
33 | npm install color-string
|
34 |
|
35 | ### browser
|
36 | Download the latest [color-string.js](https://github.com/harthur/color-string/tree/gh-pages). The `colorString` object is exported.
|