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

postcss-prefix-selector

Package Overview
Dependencies
Maintainers
3
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-prefix-selector

Prefix all CSS rules with a selector

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
126K
decreased by-66.13%
Maintainers
3
Weekly downloads
 
Created

What is postcss-prefix-selector?

The postcss-prefix-selector npm package is a PostCSS plugin that allows you to add a prefix to all CSS selectors. This can be useful for scoping styles to a specific part of a page, avoiding conflicts with other styles, or applying styles conditionally.

What are postcss-prefix-selector's main functionalities?

Prefixing all selectors

This feature allows you to add a prefix to all CSS selectors. In this example, the selector '.foo' is prefixed with '.my-prefix', resulting in '.my-prefix .foo'.

const postcss = require('postcss');
const prefixer = require('postcss-prefix-selector');

const css = '.foo { color: red; }';

postcss([prefixer({ prefix: '.my-prefix' })])
  .process(css)
  .then(result => {
    console.log(result.css);
  });
// Output: .my-prefix .foo { color: red; }

Excluding specific selectors

This feature allows you to exclude specific selectors from being prefixed. In this example, the selector '.bar' is excluded from being prefixed, so only '.foo' is prefixed.

const postcss = require('postcss');
const prefixer = require('postcss-prefix-selector');

const css = '.foo { color: red; } .bar { color: blue; }';

postcss([prefixer({ prefix: '.my-prefix', exclude: ['.bar'] })])
  .process(css)
  .then(result => {
    console.log(result.css);
  });
// Output: .my-prefix .foo { color: red; } .bar { color: blue; }

Transforming the prefix

This feature allows you to transform the prefix in a custom way. In this example, the prefix is transformed to include '--' between the prefix and the selector.

const postcss = require('postcss');
const prefixer = require('postcss-prefix-selector');

const css = '.foo { color: red; }';

postcss([prefixer({ prefix: '.my-prefix', transform: (prefix, selector, prefixedSelector) => `${prefix}--${selector}` })])
  .process(css)
  .then(result => {
    console.log(result.css);
  });
// Output: .my-prefix--.foo { color: red; }

Other packages similar to postcss-prefix-selector

Keywords

FAQs

Package last updated on 10 Oct 2024

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