
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
postcss-design-token-function
Advanced tools
A PostCSS plugin to add custom functions for accessing your design tokens.
postcss-design-token-functionA PostCSS to add custom functions for accessing your design tokens.
npm install postcss-design-token-function
In JavaScript, simply pass an object with your design token information along with the name of the function by which you will retrieve that data in your CSS. Values can be simple strings or nested objects, which are useful for cases where you have naturally nested design details (e.g., values for your color palette).
// dependencies
import fs from 'fs';
import postcss from 'postcss';
import designTokenFunction from 'postcss-design-token-function';
// css to be processed
const css = fs.readFileSync('input.css', 'utf8');
// your colors
const colors = {
white: '#F2F5FF',
blue: {
light: '#A2CEFF',
base: '#5898FF',
},
};
// process css
var output = postcss()
.use(designTokenFunction({
name: 'color',
data: colors,
}))
.process(css)
.css
And, in CSS, used the color function to reference your color palette. You can use the shade option to reference the nested shades, if provided (omitting a shade will default to using the base key of a nested color):
.foo {
background: color(white);
border: 1px solid color(blue, shade: light);
color: color(blue, base);
}
Which will generate:
.foo {
background: #F2F5FF;
border: 1px solid #A2CEFF;
color: #5898FF;
}
The following is a complete list of the possible options you can pass this plugin:
postcss().use(
designTokenFunction({
// the actual function to look for; here, `colour(white)` becomes valid.
name: 'colour',
// The design token data to reference in your function calls. Must be an object,
// optionally with multiple levels of nested objects.
data: {},
// the key to look for at any level of nesting when no variation is provided
// (and one is needed; that is, there is a nested object in your design tokens).
// By default, this plugin will look for a 'base' key.
base: 'default',
})
)
Note that you can generate functions for different design tokens by executing this plugin multiple times with each token's data provided in turn.
FAQs
A PostCSS plugin to add custom functions for accessing your design tokens.
The npm package postcss-design-token-function receives a total of 1 weekly downloads. As such, postcss-design-token-function popularity was classified as not popular.
We found that postcss-design-token-function demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.