File tree 4 files changed +32
-12
lines changed
4 files changed +32
-12
lines changed Original file line number Diff line number Diff line change 1
1
# PostCSS Hsl Color Function
2
2
3
3
[ PostCSS] plugin to transform HSL color function to more compatible CSS.
4
+ Inspired and modified from [ postcss-sass-color-functions] .
4
5
5
6
[ 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:
6
22
7
23
``` css
8
24
.foo {
9
25
color : hue (red , 120 )
10
26
}
11
27
```
12
28
29
+ After:
30
+
13
31
``` css
14
32
.foo {
15
33
color : rgb (0 , 255 , 0 )
16
34
}
17
35
```
18
36
19
- ## Usage
37
+ Checkout [ test.js ] ( index.test.js ) for examples.
20
38
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) `
24
44
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) `
Original file line number Diff line number Diff line change @@ -61,10 +61,8 @@ function transformColor(string, source) {
61
61
return string
62
62
}
63
63
var index = match . index
64
- var sassFn = match [ 2 ]
64
+ var hslFn = match [ 2 ]
65
65
66
- // NOTE: regexp search beginning of line of non char symbol before `FUNCTION(`.
67
- // Offset used for second case.
68
66
index = index === 0 ? index : index + 1
69
67
70
68
var fn = string . slice ( index )
@@ -74,6 +72,6 @@ function transformColor(string, source) {
74
72
}
75
73
76
74
return string . slice ( 0 , index ) +
77
- functions [ sassFn ] . apply ( null , balancedMatches . body . split ( / , (? ! [ ^ \( ] * \) ) / ) ) +
75
+ functions [ hslFn ] . apply ( null , balancedMatches . body . split ( / , (? ! [ ^ \( ] * \) ) / ) ) +
78
76
transformColor ( balancedMatches . post , source )
79
77
}
Original file line number Diff line number Diff line change 1
1
var postcss = require ( 'postcss' )
2
-
3
2
var plugin = require ( './' )
4
3
5
4
function run ( input , output ) {
6
- return postcss ( [ plugin ( ) ] ) . process ( input ) . then ( result => {
5
+ return postcss ( [ plugin ( ) ] ) . process ( input ) . then ( function ( result ) {
7
6
expect ( result . css ) . toEqual ( output )
8
7
expect ( result . warnings ( ) . length ) . toBe ( 0 )
9
8
} )
Original file line number Diff line number Diff line change 29
29
"jest" : " ^18.0.0"
30
30
},
31
31
"scripts" : {
32
- "lint" : " node_modules/.bin/eslint * .js" ,
32
+ "lint" : " node_modules/.bin/eslint index .js" ,
33
33
"test" : " jest" ,
34
34
"pub" : " sh release.sh"
35
35
}
You can’t perform that action at this time.
0 commit comments