classtrate
A small utility for stripping unwanted classes from HTML strings ✂️
When do you need this?
Working with genereated HTML can be a pain; you don't always have control of the output and when you
need to use that markup somewhere else you often have to perform some clean up first. This library
allows you to filter specific vendor generated classes (or IDs) to make working with HTML strings
easier. Some possible use cases:
- Reducing document size prior to HTML minification
- Preventing class collisions and other conflicts
- Cleaning output for user operations like copying and pasting
Minimum Requirements
This library makes use of
String.prototype.replaceAll()
so support for ES2021 or higher is required.
See Caniuse
Installation
Install the package:
npm install classtrate
yarn add classtrate
Usage
Import and filter with a string or glob:
import { filter } from 'classtrate';
const source = '<h1 class="br-fGy7jw my-class">My Heading</h1>';
const pattern = 'br-*';
const output = filter(source, pattern);
Features
Supports these glob features:
- Brace Expansion
- Extended glob matching
- "Globstar" ** matching