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

declassify

v2.1.0

Published

Remove any classes or IDs not found in CSS from HTML - modifies HTML, not CSS.

Downloads

6,382

Readme

declassify

Remove any classes or IDs not found in CSS from HTML - modifies HTML, not CSS.

This only considers CSS contained in the HTML document inside <style> tags to be in use right now. Currently limited to modifying class and id attributes, so won't do anything with [data] or other attributes less commonly used in CSS.

npm install declassify

Example

var declassify = require('declassify');
var result = declassify.process(html);

Input:

<html>
    <head>
        <style>
            .used-class { color: red; }
            #used-id { color: blue; }
        </style>
    </head>
    <body class="unused" style="color: black;">
        <div class="used-class unused-class"></div>
        <div id="used-id"></div>
    </body>
</html>

Output:

<html>
    <head>
        <style>
            .used-class { color: red; }
            #used-id { color: blue; }
        </style>
    </head>
    <body style="color: black;"> // has removed class="unused"
        <div class="used-class"></div> // has removed unused-class
        <div id="used-id"></div>
    </body>
</html>

Options

var declassify = require('declassify');
var options = {
  ignore: [
    'ignored-class',
    /ignored-regex-class\-[0-9]+/,
    'ignored-id',
    /ignored-regex-id\-[0-9]+/
  ],
  attrs: ['id', 'class']
};
var result = declassify.process(html, options);

Input:

<html>
    <head>
        <style>
            .used-class { color: gray; }
        </style>
    </head>
    <body id="unused-id" class="unused-class">
        <div class="unused-class ignored-class ignored-regex-class-1"></div>
        <div class="used-class ignored-class ignored-regex-class-2"></div>
        <div id="ignored-id"></div>
        <div id="ignored-regex-id-1"></div>
    </body>
</html>

Output:

<html>
    <head>
        <style>
            .used-class { color: gray; }
        </style>
    </head>
    <body>
        <div class="ignored-class ignored-regex-class-1"></div>
        <div class="used-class ignored-class ignored-regex-class-2"></div>
        <div id="ignored-id"></div>
        <div id="ignored-regex-id-1"></div>
    </body>
</html>

There are some other methods exposed by the module which can be considered public and will be considered for versioning, but please see index.js if you think you might need to use any of them.

MIT Licensed