Skip to content

Commit b6f80db

Browse files
committed
Update comment & expose transformDecl
That will allow direct usage un a plugin to avoid multiple loop to apply transformation directly in a global plugin
1 parent cd2d218 commit b6f80db

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

index.js

+24-21
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,46 @@
44
var reduceCSSCalc = require("reduce-css-calc")
55

66
/**
7-
* Expose `plugin`.
7+
* Expose plugin & helper
88
*/
9-
109
module.exports = plugin
10+
module.exports.transformDecl = transformDecl
1111

1212
/**
13-
* Plugin to convert all function calls.
14-
*
15-
* @param {Object} stylesheet
13+
* PostCSS plugin to reduce calc() function calls.
1614
*/
17-
1815
function plugin() {
1916
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+
}
2430

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
3337
}
3438
}
3539

3640
/**
37-
* Reduce CSS calc()
41+
* Reduce CSS calc() on a declaration value
3842
*
3943
* @param {String} string
4044
* @return {String}
4145
*/
42-
43-
function convert(string) {
46+
function transform(string) {
4447
if (string.indexOf("calc(") === -1) {
4548
return string
4649
}

0 commit comments

Comments
 (0)