File tree 1 file changed +24
-21
lines changed
1 file changed +24
-21
lines changed Original file line number Diff line number Diff line change 4
4
var reduceCSSCalc = require ( "reduce-css-calc" )
5
5
6
6
/**
7
- * Expose ` plugin`.
7
+ * Expose plugin & helper
8
8
*/
9
-
10
9
module . exports = plugin
10
+ module . exports . transformDecl = transformDecl
11
11
12
12
/**
13
- * Plugin to convert all function calls.
14
- *
15
- * @param {Object } stylesheet
13
+ * PostCSS plugin to reduce calc() function calls.
16
14
*/
17
-
18
15
function plugin ( ) {
19
16
return function ( style ) {
20
- style . eachDecl ( function declaration ( dec ) {
21
- if ( ! dec . value ) {
22
- return
23
- }
17
+ style . eachDecl ( transformDecl )
18
+ }
19
+ }
20
+
21
+ /**
22
+ * Reduce CSS calc on a declaration object
23
+ *
24
+ * @param {object } dec [description]
25
+ */
26
+ function transformDecl ( dec ) {
27
+ if ( ! dec . value ) {
28
+ return
29
+ }
24
30
25
- try {
26
- dec . value = convert ( dec . value )
27
- }
28
- catch ( err ) {
29
- err . position = dec . position
30
- throw err
31
- }
32
- } )
31
+ try {
32
+ dec . value = transform ( dec . value )
33
+ }
34
+ catch ( err ) {
35
+ err . position = dec . position
36
+ throw err
33
37
}
34
38
}
35
39
36
40
/**
37
- * Reduce CSS calc()
41
+ * Reduce CSS calc() on a declaration value
38
42
*
39
43
* @param {String } string
40
44
* @return {String }
41
45
*/
42
-
43
- function convert ( string ) {
46
+ function transform ( string ) {
44
47
if ( string . indexOf ( "calc(" ) === - 1 ) {
45
48
return string
46
49
}
You can’t perform that action at this time.
0 commit comments