Socket
Socket
Sign inDemoInstall

declassify

Package Overview
Dependencies
29
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    declassify

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


Version published
Weekly downloads
1.9K
increased by4.98%
Maintainers
1
Install size
1.13 MB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 02 Dec 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc