UNPKG

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