PostCSS plugin for exposing JavaScript functions.
npminstallpostcss-functionsvarfs=require('fs');varpostcss=require('postcss');varfunctions=require('postcss-functions');varoptions={//options};varcss=fs.readFileSync('input.css','utf8');postcss().use(functions(options)).process(css).then(function(result){varoutput=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:
varcolor=require('css-color-converter');require('postcss-functions')({functions: {darken: function(value,frac){vardarken=1-parseFloat(frac);varrgba=color(value).toRgbaArray();varr=rgba[0]*darken;varg=rgba[1]*darken;varb=rgba[2]*darken;returncolor([r,g,b]).toHexString();}}});.foo {
/* make 10% darker */color:darken(blue,0.1);
}Type: string|string[]
Loads files as functions based on one or more glob patterns. The function name will correspond with the file name.
Example:
require('postcss-functions')({glob: path.join(__dirname,'functions','*.js')});