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

unused-css-scanner

v1.2.1

Published

Scan React Native and React files to find unused CSS classes and StyleSheet definitions

Readme

Unused CSS Scanner 🔍

A powerful npm package to scan React Native and React files to find unused CSS classes and StyleSheet definitions.

Features

  • ✅ Scans React Native StyleSheet.create() definitions
  • ✅ Detects unused styles in your components
  • ✅ Supports .tsx, .ts, .jsx, .js files
  • ✅ Generates detailed reports with usage statistics
  • ✅ CLI and programmatic API
  • ✅ Customizable ignore patterns

Installation

npm install unused-css-scanner --save-dev
# or
yarn add unused-css-scanner --dev

Usage

Interactive Mode (Recommended)

unused-css-scanner
# or
unused-css-scanner scan

This will:

  1. Ask you which folder to scan
  2. Let you choose scan mode (all at once or one by one)
  3. Show detailed reports
  4. Ask permission to delete unused styles

Scan Specific Folder

unused-css-scanner src/

Scan Single File

unused-css-scanner src/HomeScreen.tsx

Show Help

unused-css-scanner help
# or
unused-css-scanner --help

Show Version

unused-css-scanner --version

Programmatic API

import UnusedCSSScanner from "unused-css-scanner";

// Create scanner instance
const scanner = new UnusedCSSScanner({
  files: ["src/HomeScreen.tsx", "src/Profile.tsx"],
  extensions: [".tsx", ".ts", ".jsx", ".js"],
  ignorePatterns: [/node_modules/, /\.test\./],
});

// Scan files and get results
const { results, report } = scanner.scan();

console.log(report);

// Access detailed results
results.forEach((result) => {
  console.log(`File: ${result.file}`);
  console.log(`Unused styles: ${result.unusedStyles.join(", ")}`);
});

Example with Your Code

Given this React Native component:

<View style={styles.sectionHeader}>
  <Text style={styles.sectionTitle}>Popular PGs</Text>
  <TouchableOpacity onPress={allPG}>
    <Text style={styles.seeAll}>See All →</Text>
  </TouchableOpacity>
</View>

And StyleSheet:

const styles = StyleSheet.create({
  container: { flex: 1 },
  header: { backgroundColor: Colors.primary },
  sectionHeader: { flexDirection: "row" },
  sectionTitle: { fontSize: FontSize.xxl },
  seeAll: { fontSize: FontSize.md },
  // ... more styles
});

Output:

📊 Unused CSS/Style Classes Report
══════════════════════════════════════════════════

📄 File: src/HomeScreen.tsx
   Defined: 15 | Used: 3 | Unused: 12
   ❌ Unused: container, header, searchSection, searchInput, ...

══════════════════════════════════════════════════
📈 Summary:
   Total Styles Defined: 15
   Total Styles Used: 3
   Total Styles Unused: 12
   Usage Rate: 20.00%

API Reference

UnusedCSSScanner

Constructor Options

interface ScanOptions {
  files: string[]; // Array of file paths to scan
  styleFiles?: string[]; // Optional: specific style files
  extensions?: string[]; // File extensions to scan (default: ['.tsx', '.ts', '.jsx', '.js'])
  ignorePatterns?: RegExp[]; // Patterns to ignore (default: [/node_modules/, /\.test\./])
}

Methods

  • scanFile(filePath: string): StyleUsage | null - Scan a single file
  • scanFiles(files?: string[]): StyleUsage[] - Scan multiple files
  • generateReport(results: StyleUsage[]): string - Generate text report
  • scan(files?: string[]): { results: StyleUsage[], report: string } - Scan and generate report

Return Types

interface StyleUsage {
  file: string; // File path
  definedStyles: string[]; // All defined style names
  usedStyles: string[]; // Used style names
  unusedStyles: string[]; // Unused style names
}

Configuration Examples

Ignore Specific Patterns

const scanner = new UnusedCSSScanner({
  files: ["src/**/*.tsx"],
  ignorePatterns: [/node_modules/, /\.test\./, /\.stories\./, /__snapshots__/],
});

Custom Extensions

const scanner = new UnusedCSSScanner({
  files: ["src/**/*"],
  extensions: [".tsx", ".jsx", ".ts", ".js", ".mjs"],
});

Integration with CI/CD

Add to your package.json:

{
  "scripts": {
    "lint:css": "unused-css-scanner src/**/*.tsx",
    "precommit": "npm run lint:css"
  }
}

The CLI exits with code 1 if unused styles are found, making it perfect for CI/CD pipelines.

Supported Patterns

The scanner detects:

  • style={styles.styleName}
  • style={[styles.style1, styles.style2]}
  • className="styleName"
  • className={styles.styleName}
  • Any reference to styles.styleName

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Author

Chandan Jadhav


Made with ❤️ for cleaner React Native codebases

npm version npm downloads