Skip to content

Commit 0ce7ea5

Browse files
update README
1 parent 8acb1f7 commit 0ce7ea5

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,48 @@
11
# PostCSS Hsl Color Function
22

33
[PostCSS] plugin to transform HSL color function to more compatible CSS.
4+
Inspired and modified from [postcss-sass-color-functions].
45

56
[PostCSS]: https://github.com/postcss/postcss
7+
[postcss-sass-color-functions]: https://github.com/adam-h/postcss-sass-color-functions
8+
9+
## Installation
10+
11+
```console
12+
$ npm install postcss-hsl-color-function
13+
```
14+
15+
## Usage
16+
17+
```js
18+
postcss([require('postcss-hsl-color-function')])
19+
```
20+
21+
Before:
622

723
```css
824
.foo {
925
color: hue(red, 120)
1026
}
1127
```
1228

29+
After:
30+
1331
```css
1432
.foo {
1533
color: rgb(0, 255, 0)
1634
}
1735
```
1836

19-
## Usage
37+
Checkout [test.js](index.test.js) for examples.
2038

21-
```js
22-
postcss([ require('postcss-hsl-color-function') ])
23-
```
39+
### Currently supported functions
40+
41+
- `hue(color, degree)`
42+
- `saturation(color, percentage)`
43+
- `lightness(color, percentage)`
2444

25-
See [PostCSS] docs for examples for your environment.
45+
and their aliases:
46+
- `h(color, degree)`
47+
- `s(color, percentage)`
48+
- `l(color, percentage)`

index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,8 @@ function transformColor(string, source) {
6161
return string
6262
}
6363
var index = match.index
64-
var sassFn = match[2]
64+
var hslFn = match[2]
6565

66-
// NOTE: regexp search beginning of line of non char symbol before `FUNCTION(`.
67-
// Offset used for second case.
6866
index = index === 0 ? index : index + 1
6967

7068
var fn = string.slice(index)
@@ -74,6 +72,6 @@ function transformColor(string, source) {
7472
}
7573

7674
return string.slice(0, index) +
77-
functions[sassFn].apply(null, balancedMatches.body.split(/,(?![^\(]*\))/)) +
75+
functions[hslFn].apply(null, balancedMatches.body.split(/,(?![^\(]*\))/)) +
7876
transformColor(balancedMatches.post, source)
7977
}

index.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
var postcss = require('postcss')
2-
32
var plugin = require('./')
43

54
function run(input, output) {
6-
return postcss([plugin()]).process(input).then(result => {
5+
return postcss([plugin()]).process(input).then(function(result) {
76
expect(result.css).toEqual(output)
87
expect(result.warnings().length).toBe(0)
98
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"jest": "^18.0.0"
3030
},
3131
"scripts": {
32-
"lint": "node_modules/.bin/eslint *.js",
32+
"lint": "node_modules/.bin/eslint index.js",
3333
"test": "jest",
3434
"pub": "sh release.sh"
3535
}

0 commit comments

Comments
 (0)