function() plugin for rework, formerly included in core
Add user-defined CSS functions.
For example create black(0.5) shortcut, to replace
long rgba(0, 0, 0, 0.5).
varrework=require('rework'),varreworkFunction=require('rework-plugin-function');varcss=rework(css).use(reworkFunction({black: black})).toString()functionblack(opacity){return'rgba(0, 0, 0, '+opacity+')';}User code will receive CSS arguments and replace user-defined function by returned code.
input {
box-shadow:005pxblack(0.7);
}yields:
input {
box-shadow:005pxrgba(0,0,0,0.7);
}Nested functions works well too:
varcss=rework(css).use(reworkFunction({subtract: function(a,b){returna-b},multiply: function(a,b){returna*b},divide: function(a,b){returna/b},floor: Math.floor})).toString()input {
top:divide(subtract(30,floor(multiply(20,10))),2);
}Would yield:
input {
top:-85;
}