npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postcss-pseudo-element-colons

v1.0.2

Published

PostCSS plugin to format single or double colon notation on pseudo elements.

Downloads

673

Readme

PostCSS Pseudo-Element Colons

PostCSS plugin to format single or double colon notation on pseudo elements.

Turn .fancy-style:before { into .fancy-style::before { and vice versa.

Jump To Section


Installation

$ npm install postcss-pseudo-element-colons --save-dev

Note: This plugin is for PostCSS.

Usage

With postcss-cli

$ postcss --use postcss-pseudo-element-colons style.css

With Node.js:

var fs           = require( 'fs' ),
    postcss      = require( 'postcss' ),
    pseudoColons = require( 'postcss-pseudo-element-colons' );

const
  options = {
    "selectors": [
        "before",
        "after",
        "first-letter",
        "first-line"
    ],
    "colon-notation": "single"
  };

fs.readFile( 'style.css', ( err, css ) => {
  postcss( [pseudoColons( options )] )
    .process( css, {
      from: 'style.css',
      to: '/style.css'
    }).then( result => {
      fs.writeFile( 'style.css', result.css,
        ( err ) => {
          if ( err ) throw err;
        });
    }).catch( ( err ) => {
      console.log( err );
    });
});

Grunt with grunt-postcss

Running default options:

module.exports = function( grunt ) {
  grunt.initConfig({
    postcss: {
      options: {
        processors: [
          require( 'postcss-pseudo-element-colons' )
        ]
      },
      dist: {
        src: 'src/style.css',
        dest: 'dist/style.css'
      }
    }
  });

  grunt.loadNpmTasks( 'grunt-postcss' );
};

Running custom options:

module.exports = function( grunt ) {
  grunt.initConfig({
    postcss: {
      options: {
        processors: [
          require( 'postcss-pseudo-element-colons' )({
            "selectors": [
                "before",
                "after"
            ],
            "colon-notation": "single"
          })
        ]
      },
      dist: {
        src: 'src/style.css',
        dest: 'dist/style.css'
      }
    }
  });

  grunt.loadNpmTasks( 'grunt-postcss' );
};

Gulp.js with gulp-postcss

var gulp         = require( 'gulp' );
var postcss      = require( 'gulp-postcss' );
var pseudoColons = require( 'postcss-pseudo-element-colons' );

const
  options = {
    "selectors": [
        "before",
        "after",
        "first-letter",
        "first-line"
    ],
    "colon-notation": "single"
  };

gulp.task( 'postcss', function(){
	gulp.src( 'src/style.css' )
		.pipe( postcss( [ pseudoColons( options ) ] ) )
		.pipe( gulp.dest( 'dist' ) );
});

Options

Default Options:

{
  "selectors": [
      "before",
      "after",
      "first-letter",
      "first-line"
  ],
  "colon-notation": "double"
}

selectors

Accepts array of pseudo-elements which should have single or double colon syntax enforced in stylesheet.

Defaults to ["before", "after", "first-letter", "first-line"].

colon-notation

Accepts "single" or "double" for the psudeo-element's colon notation.

"single" produces syntax like: .fancy-style:before {

"double" produces syntax like .fancy-style::before {

Examples

Enforced Double Colon

Before enforcing the double colon option ( default ):

.fancy-style:first-line {
  font-variant: small-caps;
}
.fancy-style:before, .fancy-style::after {
  content: "";
}
.fancy-style:first-letter {
  color: blue;
}

After running the PostCSS plugin:

.fancy-style::first-line {
  font-variant: small-caps;
}
.fancy-style::before, .fancy-style::after {
  content: "";
}
.fancy-style::first-letter {
  color: blue;
}

Enforced Single Colon

Before enforcing the single colon option:

.fancy-style::first-line {
  font-variant: small-caps;
}
.fancy-style::before, .fancy-style:after {
  content: "";
}
.fancy-style::first-letter {
  color: blue;
}

After running the PostCSS plugin:

.fancy-style:first-line {
  font-variant: small-caps;
}
.fancy-style:before, .fancy-style:after {
  content: "";
}
.fancy-style:first-letter {
  color: blue;
}