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 🙏

© 2026 – Pkg Stats / Ryan Hefner

extract-inline-style

v0.1.1

Published

Extracts inline style attributes (style="...") from HTML elements, moves them to an external CSS file, and deduplicates identical styles.

Readme

extract-inline-style

Turn spaghetti code into clean code instantly. Extracts inline style="..." attributes, deduplicates them into atomic classes, and cleans your HTML.

npm version npm downloads npm version

Pain Point: You have a legacy HTML file, an email template, or scraped content. It looks like this:

<div style="font-size: 14px; color: #fff; margin-bottom: 10px;">Hello</div>
<div style="font-size: 14px; color: #333; margin-bottom: 10px;">World</div>
<div style="font-size: 14px; color: #555; margin-bottom: 10px;">!</div>

It's unreadable. It's bloated. It's impossible to maintain.

The Solution: Run npx extract-inline-style index.html. The tool analyzes your code and:

  1. Surgically Removes the inline styles.
  2. Deduplicates them (Compression). It sees those 3 divs are identical.
  3. Generates a single, semantic class.
  4. Injects the stylesheet link automatically.
  5. Backs up your original file (just in case).

The Result:

<head>
  <link rel="stylesheet" href="./index-extracted.css">
</head>
<body>
  <div class="eis-div-1">Hello</div>
  <div class="eis-div-1">World</div>
  <div class="eis-div-1">!</div>
</body>

Your file size just dropped, and your sanity just increased.

Features

  • Universal Parser: Works on HTML files, fragments, and even HTML embedded in Markdown.
  • Smart Compression: 1,000 elements with the same style = 1 CSS Class.
  • Semantic Naming: Classes are named by tag (e.g., eis-button-1, eis-span-2) for easy debugging.
  • Safety First: Automatic .original.html backups. Never lose data.
  • API Ready: Perfect for content pipelines and static site generators.

Installation

npm install extract-inline-style

Usage

CLI

# Auto-generate CSS filename (index-extracted.css)
npx extract-inline-style index.html

# Specify output CSS filename
npx extract-inline-style index.html my-styles.css

CLI Options

| Flag | Alias | Description | Default | | :--- | :--- | :--- | :--- | | --prefix | -p | Custom prefix for generated classes. | eis- | | --no-backup | | Skip creating the .original.html backup file. | false | | --no-inject | | Do not add <link> tag to HTML head. | false | | --version | -v | Show version number. | | | --help | -h | Show help usage. | |

API

Perfect for build tools, static site generators, or content pipelines. The API operates on strings and returns strings (it does not write to disk).

import { extract } from 'extract-inline-style';

const html = `
  <h1 style="color: blue">Hello</h1>
  <p style="color: blue">World</p>
`;

// Run extraction
const result = extract(html, { 
  classPrefix: 'theme-',
  injectCssPath: './styles.css' 
});

console.log(result.html);
// <head><link rel="stylesheet" href="./styles.css"></head>
// ...
// <h1 class="theme-h1-1">Hello</h1>
// <p class="theme-p-2">World</p>

console.log(result.css);
// .theme-h1-1 { color: blue; }
// .theme-p-2 { color: blue; }

API Options

The extract(html, options) function accepts an optional configuration object:

| Option | Type | Description | Default | | :--- | :--- | :--- | :--- | | classPrefix | string | Prefix for generated CSS classes. | 'eis-' | | injectCssPath | string | If provided, injects a <link rel="stylesheet"> tag pointing to this path. | undefined |

Return Value

The function returns an object containing:

{
  html: string;  // The cleaned HTML string
  css: string;   // The generated CSS string
  stats: {
    elementsProcessed: number; // How many inline styles were found
    uniqueClasses: number;     // How many unique classes were generated
  }
}

License

MIT

{ github.com/mgks }

Website Badge Sponsor Badge