🚀 Socket Launch Week 🚀 Day 1: Introducing .NET Support in Socket.Learn More
Socket
Sign inDemoInstall
Socket

prefixify-css

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prefixify-css

Reads a CSS file meant for 'global context' and prefixes each selector with a specified selector, wrapping the remainder in :global()

1.0.1
latest
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

prefixify-css

Reads a CSS file meant for 'global context' and prefixes each selector with a specified selector, wrapping the remainder in :global()

.SomeLibrary .wrapper {
  width: 100%;
}
.SomeLibrary-blah li:nth-child(5) {
  opacity: 0.5;
}

/* Becomes */

.myPrefix :global(.SomeLibrary .wrapper) {
  width: 100%;
}
.myPrefix :global(.SomeLibrary-blah li:nth-child(5)) {
  opacity: 0.5;
}

This is useful when using CSS Modules and you want to include something like CodeMirror, Leaflet and other libraries which has CSS which are globally scoped, but you want to at the very least contain it to within one of your classes.

Installation

As a CLI tool:

npm install -g prefixify-css

or, if you want to use it programatically:

npm install prefixify-css

Usage (CLI)

$ prefixify

  prefixify-css: Reads a CSS file meant for 'global context' and prefixes each selector with a specified selector, wrapping the remainder in :global()

  The result is written to stdout.

  Usage
    $ prefixify <input> <selector>

  Examples
    $ prefixify leaflet.css '.leafletInput' > prefixed.css
    $ prefixify - '.leafletInput' < cat /path/to/leaflet.css

Alternatively, you can run it through npx without even having to install it:

$ npx prefixify-css myFile.css .mySelector

Usage (JavaScript API)

const prefixify = require('prefixify-css')

prefix({
  content: '.CodeMirror { width: 100%; }',
  selector: '.myClass',
})
  .then((result) => {
    // .myClass :global(.CodeMirror) { width: 100%; }
    console.log(result)
  })
  .catch((error) => {
    console.error(error)
  })

License

MIT © Espen Hovlandsdal

Keywords

postcss

FAQs

Package last updated on 13 Apr 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