4.0.2 • Published 5 years ago

postcss-functions v4.0.2

Weekly downloads
688,219
License
MIT
Repository
github
Last release
5 years ago

postcss-functions

PostCSS plugin for exposing JavaScript functions.

Installation

npm install --save-dev postcss postcss-functions

Usage

import fs from 'fs';
import postcss from 'postcss';
import functions from 'postcss-functions';

const options = {
	//options
};

const css = fs.readFileSync('input.css', 'utf8');

postcss()
  .use(functions(options))
  .process(css)
  .then((result) => {
    const output = result.css;
  });

Example of a function call:

body {
  prop: foobar();
}

Options

functions

Type: Object

An object containing functions. The function name will correspond with the object key.

Example:

import postcssFunctions from 'postcss-functions';
import { fromString, fromRgb } from 'css-color-converter';
function darken(value, frac) {
  const darken = 1 - parseFloat(frac);
  const rgba = fromString(value).toRgbaArray();
  const r = rgba[0] * darken;
  const g = rgba[1] * darken;
  const b = rgba[2] * darken;
  return fromRgb([r,g,b]).toHexString();
}
postcssFunctions({
  functions: { darken }
});
.foo {
  /* make 10% darker */
  color: darken(blue, 0.1);
}

Hey, what happened to glob?

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.

vue-steps-k@dubb/mickey@ihikmawan/tailwindcss-multi-theme-l2widget-engine@infinitebrahmanuniverse/nolb-postcss-ftailwindcss-with-commentstailwindcss-wo-normalize@everything-registry/sub-chunk-2460webfile-packerreact-application-servertailwindcss-wontailwindcss-tachyonstailwind-vector-effectv-custom-stepsv-svg-chainvaria-clientvue-cli-plugin-sflegovue-cli-plugin-vusion@deflock/assettler-processor-modularcsssquashfold-uitrb-tailwindcss@arxpoetica/sapper-trimmings@chassis/core@brandocms/europacss@delement/ui@davidwells/config-postcssvc-webpack-vendors@dumc11/tailwindcss@dubb/junior@hckr_/blendid@happysouls/checkout-ui-react@forchange/cli-service@ihikmawan/tailwindcss-multi-theme-iman-test@ihikmawan/tailwindcss-multi-theme-v2@everledger/js-toolchain@lowb/react-scripts@mostlyserious/brightpack@max-norin/postcss-project-init@megadeluxe/topcoat@jfkued/min-cli@dword-design/atomizer-plugin-vertical-rhythm@sapper-dragon/postcss@spectrum-css/build@shopify/post-purchase-ui-react@shopify/checkout-ui-reactovercoatsassyboinewcsslibpineglade-apppostcss-image-set-generatorpostcss-imagerpostcss-hash-urlpostcss-tiger-riapostcss-loadpostcss-plugin-hsluvpostcss-prefix-urlpostcss-atom-starpostcss-assetspostcss-mixreacteekhdyeuslwodkhygsleyserplus-postcss-assetslitepie-datepicker-gabemake-extension@univers-agency/europacss@zalastax/nolb-postcss-f@tailwindcss/postcss7-compataokacsschromatic-postcsscli-serviceember-assemblyember-goodsequip-resources-basestylesfirefly-uifis3-parser-precssfreehand@sevinf/tailwindcss
4.0.1

5 years ago

4.0.0

5 years ago

4.0.2

5 years ago

3.0.0

8 years ago

3.0.0-beta.2

8 years ago

3.0.0-beta.1

8 years ago

3.0.0-beta.0

8 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.0

10 years ago

1.0.0

10 years ago