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

posthtml-classes

v0.2.1

Published

PostHTML-plugin to retrieve a list of classes from html with support of nested structure

Downloads

8

Readme

PostHTML-classes

npm version

PostHTML-plugin to retrieve a list of classes from html file(s) with support of nested structure (PostCSS, Stylus, SASS, SCSS, LESS)

Install

$ npm install --save-dev posthtml-classes

Usage

var posthtml = require('posthtml'),
    config = {
        fileSave: true,
        filePath: './classList.css',
        overwrite: false,
        eol: '\n',
        nested: false,
        curlbraces: true,
        elemPrefix: '__',
        modPrefix: '_',
        modDlmtr: '_'
    },
    html = '<div block="mad-tea-party"><div elem="march-hare" mods="type:mad">March Hare</div><div elem="hatter" mods="type:mad">Hatter</div><div elem="dormouse" mods="state:sleepy">Dormouse</div></div>';

posthtml()
    .use(require('posthtml-classes')(config))
    .process(html);
    //classList.css
    //.mad-tea-party {}
    //.mad-tea-party__march-hare {}
    //.mad-tea-party__march-hare_type_mad {}
    //.mad-tea-party__hatter {}
    //.mad-tea-party__hatter_type_mad {}
    //.mad-tea-party__dormouse {}
    //.mad-tea-party__dormouse_state_sleepy {}

or with support of nested structure

var posthtml = require('posthtml'),
    config = {
        fileSave: true,
        filePath: './classList.css',
        overwrite: false,
        eol: '\n',
        nested: false,
        curlbraces: true,
        elemPrefix: '__',
        modPrefix: '_',
        modDlmtr: '_'
    },
    html = '<div class="animal"><div class="animal__nose animal__nose_size_long elephant__trunk elephant__trunk_size_short elephant__trunk_color_brown">Nose</div></div>';

posthtml()
    .use(require('posthtml-classes')(config))
    .process(html);
    //classList.css
<!-- .animal {
        &__nose {
            &_size_long {}
        }
     }
     .elephant {
        &__trunk {
            &_size_short {}
            &_color_brown {}
        }
     }
-->

Options

fileSave

Type: boolean
Default: true

Set true if you want to save the file, or false if you want to copy to clipboard (Mac/Win/Linux).

filePath

Type: string
Default: ./classList.css

The filename and path of the saved file

overwrite

Type: boolean
Default: false

Set true if you want to save to the same file - the data in this file will be overwritten, or false if you want to save to a different file each time - the file will be have random id (i.e. classList_0394.css)

eol

Type: string
Default: \n

Characters that are added to the end of the CSS rule

nested

Type: boolean
Default: false

Set true if you want to generate css file with support of nested structure, which supported by PostCSS, Stylus, SCSS or LESS preprocessor, or false if you want to generate standard css.

curlybraces

Type: boolean
Default: true

Set true if you want to use curly braces, or false if you want to generate without them, for example for SASS or Stylus

elemPrefix

Type: string
Default: __

Characters that can be used for delimiter of element

modPrefix

Type: string
Default: _

Characters that can be used for delimiter of modifiers

modDlmtr

Type: string
Default: _

Characters that can be used for the separator modifier values

With Gulp

var gulp = require('gulp'),
    posthtml = require('gulp-posthtml');

gulp.task('default', function () {
    return gulp.src('test.html')
        .pipe(posthtml([
            require('posthtml-classes')({
                fileSave: true,
                filePath: './classList.css',
                overwrite: false,
                eol: '\n',
                nested: false
            })
        ]));
});

License

MIT