PostCSS plugin for exposing JavaScript functions.
npminstall--save-devpostcsspostcss-functionsimportfsfrom'fs';importpostcssfrom'postcss';importfunctionsfrom'postcss-functions';constoptions={//options};constcss=fs.readFileSync('input.css','utf8');postcss().use(functions(options)).process(css).then((result)=>{constoutput=result.css;});Example of a function call:
body {
prop:foobar();
}Type: Object
An object containing functions. The function name will correspond with the object key.
Example:
importpostcssFunctionsfrom'postcss-functions';import{fromString,fromRgb}from'css-color-converter';functiondarken(value,frac){constdarken=1-parseFloat(frac);constrgba=fromString(value).toRgbaArray();constr=rgba[0]*darken;constg=rgba[1]*darken;constb=rgba[2]*darken;returnfromRgb([r,g,b]).toHexString();}postcssFunctions({functions: { darken }});.foo {
/* make 10% darker */color:darken(blue,0.1);
}Versions prior to 4.0.0 had a globbing feature built in, but I've since decided to remove this feature from postcss-functions. This means one less dependency and a smaller package size. For people still interested in this feature, you are free to pair postcss-functions with the globbing library of your choice and pass the imported JavaScript files to the functions option as described above.