Registry / devops / class-id-minifier

class-id-minifier

JSON →
library0.4.0jsnpmunverified

Minify class and id attribute values in HTML strings by renaming them to short, unique tokens. Version 0.4.0 is the latest stable release. The package has a low release cadence and minimal maintenance. It transforms class and id attributes in HTML, but does not update corresponding CSS selectors or JavaScript references, which is a common footgun.

npm install class-id-minifier
INSTALL
IMPORT
SIG · CLASS-ID-MINIFIER
C
class-id-minifier
devopsjavascriptv0.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import minifier from 'class-id-minifier';
const minifier = require('class-id-minifier');
The package is ESM-only. CommonJS require will fail.
minify
import { minify } from 'class-id-minifier';
const { minify } = require('class-id-minifier');
Named export minify is available. If using CJS, use dynamic import.
minifier
const minifier = (await import('class-id-minifier')).default;
const minifier = require('class-id-minifier');
For CommonJS, use dynamic import() to access the default export.

Demonstrates minifying class attribute values using the named import minify.

import { minify } from 'class-id-minifier'; const html = `<div class="my-class another-class">content</div>`; const result = minify(html); console.log(result); // <div class="a b">content</div>
Debug
Known issues
gotchaClass and ID values are minified, but corresponding CSS selectors or JavaScript references are not updated. You must handle those separately.
fix
Post-process CSS and JS to replace old class/id names with new ones using a mapping returned by the minifier.
affects: >=0.1.0 <=0.4.0
gotchaThe minifier does not handle inline style attributes or script tags. Any class/id references inside <style> or <script> will not be updated.
fix
Extract and process style and script content separately.
affects: >=0.1.0 <=0.4.0
gotchaUndefined behavior if class or id attribute values contain spaces or special characters. The minifier may produce invalid tokens.
fix
Ensure class and id values are standard CSS identifiers (no spaces except between multiple classes).
affects: >=0.1.0 <=0.4.0
Errors
Common errors & fixes
Cannot find module 'class-id-minifier'
Package is ESM-only, but you are using require() which is CJS.
fix
Use dynamic import: const minifier = (await import('class-id-minifier')).default;
TypeError: minifier is not a function
You imported the module but used default import when you should use named import minify.
fix
Use import { minify } from 'class-id-minifier' instead of import minifier from ...
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
class-id-minifier — npm install class-id-minifier · libregistry