postcss-functions

WebJar for postcss-functions

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

postcss-functions
Last Version

Last Version

4.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

postcss-functions
WebJar for postcss-functions
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/andyjansson/postcss-functions

Download postcss-functions

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/postcss-functions/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>postcss-functions</artifactId>
    <version>4.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/postcss-functions/
implementation 'org.webjars.npm:postcss-functions:4.0.2'
// https://jarcasting.com/artifacts/org.webjars.npm/postcss-functions/
implementation ("org.webjars.npm:postcss-functions:4.0.2")
'org.webjars.npm:postcss-functions:jar:4.0.2'
<dependency org="org.webjars.npm" name="postcss-functions" rev="4.0.2">
  <artifact name="postcss-functions" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='postcss-functions', version='4.0.2')
)
libraryDependencies += "org.webjars.npm" % "postcss-functions" % "4.0.2"
[org.webjars.npm/postcss-functions "4.0.2"]

Dependencies

compile (1)

Group / Artifact Type Version
org.webjars.npm : postcss-value-parser jar [4.0.0,5)

Project Modules

There are no modules declared in this project.

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.

Versions

Version
4.0.2
4.0.1
4.0.0
3.0.0