Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-functions

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-functions

PostCSS plugin for exposing JavaScript functions

  • 4.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
125K
decreased by-44.69%
Maintainers
1
Weekly downloads
 
Created

What is postcss-functions?

The postcss-functions npm package allows you to define and use custom functions within your CSS. This can be useful for a variety of tasks such as calculations, transformations, and dynamic value generation.

What are postcss-functions's main functionalities?

Custom Function Definitions

This feature allows you to define custom functions that can be used within your CSS. In the example, a function `calcWidth` is defined to add two pixel values together.

const postcss = require('postcss');
const functions = require('postcss-functions');

const css = `
  .example {
    width: calcWidth(100px, 50px);
  }
`;

const output = postcss([
  functions({
    functions: {
      calcWidth: (value1, value2) => {
        return parseFloat(value1) + parseFloat(value2) + 'px';
      }
    }
  })
]).process(css).css;

console.log(output);

Dynamic Value Generation

This feature allows you to generate dynamic values within your CSS. In the example, a function `dynamicColor` is defined to generate a random color.

const postcss = require('postcss');
const functions = require('postcss-functions');

const css = `
  .example {
    color: dynamicColor();
  }
`;

const output = postcss([
  functions({
    functions: {
      dynamicColor: () => {
        return '#'+Math.floor(Math.random()*16777215).toString(16);
      }
    }
  })
]).process(css).css;

console.log(output);

String Manipulation

This feature allows you to manipulate strings within your CSS. In the example, a function `appendText` is defined to concatenate two strings.

const postcss = require('postcss');
const functions = require('postcss-functions');

const css = `
  .example {
    content: appendText('Hello', ' World');
  }
`;

const output = postcss([
  functions({
    functions: {
      appendText: (text1, text2) => {
        return `'${text1 + text2}'`;
      }
    }
  })
]).process(css).css;

console.log(output);

Other packages similar to postcss-functions

Keywords

FAQs

Package last updated on 08 Nov 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc