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

postcss-namespace

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-namespace

PostCSS plugin that prefix a namespace to a selector

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

postcss-namespace

npm version Build Status XO code style

PostCSS plugin that prefix a namespace to a selector


Install

npm i postcss-namespace

Usage

Write @prefix atrule to your css file. (e.g. input.css)

.outside {}

@prefix block not(.not-target, /ignore/);

.box {}

.inner .target {}
.inner .not-target {}
.inner .ignore-1 {}
.inner .ignore-2,
.inner .target {}

@prefix ;

.box {}

@prefix block2;

.box {}
&:hover {}
[href^="https"][target="_blank"] {}

@media screen and (min-width: 768px) {
  #media {}
  #media #inner,
  .media .inner.box {}
}

Use this plugin in PostCSS (e.g.)

const fs = require('fs');
const postcss = require('postcss');
const namespace = require('postcss-namespace');

const css = fs.readFileSync('./sample.css', 'utf-8');

// or postcss([namespace.bem])
postcss([namespace({token: '__'})])
  .process(css)
  .then(result => console.log(result.css));

Will get output like following CSS

.outside {}

.block__box {}

.block__inner .block__target {}
.block__inner .not-target {}
.block__inner .ignore-1 {}
.block__inner .ignore-2,
.block__inner .block__target {}

.box {}

.block2__box {}
&:hover {}
[href^="https"][target="_blank"] {}

@media screen and (min-width: 768px) {
  #block2__media {}
  #block2__media #block2__inner,
  .block2__media .block2__inner.block2__box {}
}

AtRule Function

  • not (string|regexp)...
    Specify selector or pattern which Don't want a prefix

Plugin Function

  • namespace.bem
    Same as namespace({token: '__'})

Options

  • token
    Token for consolidate(e.g.) namespace({token: '__'})
    - by default

Run to example

1 Close this

git clone git@github.com:totora0155/postcss-namespace.git

2 Change directory

cd postcss-namespace

3 Install modules

npm install

4 Run to script

cd examples && node postcss.js

Change log

versionlog
1.1.0Add bem function. (Alias {token: '__'})
1.0.1Fix node.nodes
1.0.0Rewrite with es2015 & Add not func in AtRule
0.2.5Bug fix for :nth* selector & Revert v0.2.2
0.2.4Bug fix for pseudo selector
0.2.3Bug fix (Tag not output after atrule)
0.2.2Fix, occured error to postcss-selector-not syntax
0.2.0Change at-rule keyword to @prefix from @namespace #1

Keywords

FAQs

Package last updated on 08 Jul 2016

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