# postcss-functions

> PostCSS plugin for exposing JavaScript functions

Latest version **4.0.2** (published 2020-11-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-functions
pnpm add postcss-functions
yarn add postcss-functions
bun add postcss-functions
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.2 |
| Published | 2020-11-08 |
| First published | 2015-08-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/postcss-functions) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 214 |
| Author | Andy Jansson |
| Maintainers | andyjansson |
| Keywords | postcss, postcss-plugin, javascript, function, functions |

## Links

- npm: https://www.npmjs.com/package/postcss-functions
- Repository: https://github.com/andyjansson/postcss-functions
- Issues: https://github.com/andyjansson/postcss-functions/issues
- npm.io page: https://npm.io/package/postcss-functions

## Dependencies (1)

- [postcss-value-parser](https://npm.io/package/postcss-value-parser.md) ^4.0.0

## Recent versions

- 4.0.2 (latest) — 2020-11-08
- 3.0.0-beta.2 (next) — 2017-08-09
- 4.0.1 — 2020-11-08
- 4.0.0 — 2020-11-08
- 3.0.0 — 2017-08-13
- 3.0.0-beta.1 — 2017-08-08
- 3.0.0-beta.0 — 2017-08-08
- 2.1.1 — 2016-10-08
- 2.1.0 — 2016-01-28
- 2.0.0 — 2015-11-09
- 1.0.0 — 2015-08-04

## README

# postcss-functions

[PostCSS] plugin for exposing JavaScript functions.

[PostCSS]: https://github.com/postcss/postcss

## Installation

```js
npm install --save-dev postcss postcss-functions
```

## Usage

```js
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:

```css
body {
  prop: foobar();
}
```

## Options

### `functions`

Type: `Object`

An object containing functions. The function name will correspond with the object key.

**Example:**

```js
import postcssFunctions from 'postcss-functions';
import { fromString, fromRgb } from 'css-color-converter';
```

```js
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();
}
```

```js
postcssFunctions({
  functions: { darken }
});
```

```css
.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 `import`ed JavaScript files to the `functions` option as described above.

---
_Source: https://npm.io/package/postcss-functions · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
