Registry / productivity / email-minifier

email-minifier

JSON →
library1.0.5jsnpmunverified

EmailMinifier (v1.0.5) is a TypeScript-based email minifier for browser and Node.js that specializes in reducing email HTML size, unlike generic HTML minifiers. It minifies IDs, classes, data-* attributes, and CSS within style tags, and can remove unused custom attributes. Version 1.0.5 is the latest stable release; maintainers commit irregularly. Key differentiators include handling email-specific constraints (no JS, limited interactivity, Gmail cropping) and providing a simple async API.

npm install email-minifier
INSTALL
IMPORT
SIG · EMAIL-MINIFIER
E
email-minifier
productivityjavascriptv1.0.5
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.

EmailMinifier
import { EmailMinifier } from 'email-minifier'
import EmailMinifier from 'email-minifier'
This package only exports a named export, not a default export. Using a default import will work in some bundlers but may fail in pure ESM environments.
EmailMinifier (CommonJS)
const { EmailMinifier } = require('email-minifier')
const EmailMinifier = require('email-minifier')
CommonJS users must destructure the require result to get the named export. Assigning the whole require to a variable yields an object, not the class.
EmailMinifier (dynamic import)
const { EmailMinifier } = await import('email-minifier')
const EmailMinifier = await import('email-minifier')
Dynamic import also returns an object with the named export; destructure it to get the class.

Shows how to import EmailMinifier, create an instance with an email HTML string, call minify() with options, and access the minified result, original size, and tasks.

import { EmailMinifier } from 'email-minifier'; const emailBody = `<div class="hello" style="color:red;"></div>`; const options = { minifyIds: true, minifyClasses: true, minifyDatasets: true, removeUnusedAttrs: false, minifyStyles: true }; const minifier = new EmailMinifier(emailBody); const result = await minifier.minify(options); console.log('Minified:', result.minified); console.log('Original size:', result.original.length); console.log('Tasks executed:', result.tasks);
Debug
Known issues
gotchaThe minify() method returns a Promise, not the result directly.
fix
Always await or use .then() when calling minify().
affects: >=0.0.0
gotchaIf minify() finds nothing to minify, result.minified will be null, not the original string.
fix
Check for null before using result.minified, or fallback to result.original.
affects: >=0.0.0
gotchaThe removeUnusedAttrs option can be a boolean or an array of RegExp. Passing a non-RegExp array will cause errors.
fix
Ensure array elements are RegExp instances, e.g., [new RegExp('custom-test-id')].
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: email_minifier_1.EmailMinifier is not a constructor
Default import used when the package only exports a named export.
fix
Use named import: import { EmailMinifier } from 'email-minifier'
Cannot find module 'email-minifier'
Package not installed or import path incorrect.
fix
Run npm install email-minifier and ensure the import is exactly 'email-minifier'.
TypeError: Cannot destructure property 'EmailMinifier' of 'require(...)' as it is undefined.
Using require('email-minifier') in an ESM context or package not installed.
fix
For CommonJS, use const { EmailMinifier } = require('email-minifier'). For ESM, use import.
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
28 hits · last 30 days
node
26
OpenAI (training)
1
Resources
email-minifier — npm install email-minifier · libregistry