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

import-unifier

v1.0.2

Published

Generic import consolidator for TypeScript projects. Merge imports from a source path into a target file.

Readme

import-unifier

Generic Import Consolidator for TypeScript Projects

import-unifier helps streamline imports by consolidating them from a source path into a single target file. It works seamlessly with any TypeScript project, keeping your imports clean, consistent, and maintainable.


✨ Features

  • 🔄 Consolidates imports from any source path into one target file
  • 🔗 Merges named and default imports automatically
  • 📁 Creates the target file automatically if it doesn't exist
  • 🎯 Supports TypeScript (.ts) and TSX (.tsx) files
  • 🛠️ Provides both CLI and programmatic usage
  • 📊 Logs processed files for easy tracking
  • 🧹 Improves codebase maintainability by avoiding duplicate imports and clutter

📦 Installation

# Using npm
npm install import-unifier --save-dev

# Using yarn
yarn add import-unifier --dev

🚀 Usage

Programmatic Usage

import { consolidateImports } from "import-unifier";

consolidateImports({
  tsConfigPath: "tsconfig.json",                // optional (default: tsconfig.json)
  sourceGlob: "src/**/*.tsx",                   // optional (default: src/**/*.ts{,x})
  sourcePath: "src/components/",                // required: folder to consolidate from
  targetPath: "src/shared/components/index",    // required: target file path
  log: true                                     // optional (default: true)
});

How it works:

  • Scans all files under sourceGlob
  • Collects imports from sourcePath
  • Rewrites imports to point to targetPath
  • Merges imports into the target file (index.ts)

CLI Usage

npx consolidate-imports <tsConfigPath?> <sourcePath> <targetPath>

Arguments:

  • tsConfigPath (optional): Path to your TypeScript config (default: tsconfig.json)
  • sourcePath (required): Folder or module path to consolidate imports from
  • targetPath (required): File path where consolidated imports will be merged

Example:

npx consolidate-imports tsconfig.json src/components/ src/shared/components/index

📋 Example

Before consolidation:

// src/pages/Home.tsx
import { Button } from "src/components/Button";
import { Card } from "src/components/Card";
import { Modal } from "src/components/Modal";

// src/pages/Dashboard.tsx
import { Button } from "src/components/Button";
import { Table } from "src/components/Table";

After running import-unifier:

// src/pages/Home.tsx
import { Button, Card, Modal } from "src/shared/components/index";

// src/pages/Dashboard.tsx
import { Button, Table } from "src/shared/components/index";

// src/shared/components/index.ts (auto-generated)
export { Button } from "../../components/Button";
export { Card } from "../../components/Card";
export { Modal } from "../../components/Modal";
export { Table } from "../../components/Table";

All imports from the source folder are merged into a single import pointing to the target file, making your codebase cleaner and more maintainable.


🎯 Use Cases

  • Component Libraries: Consolidate component imports into a single index file
  • Utility Functions: Merge utility imports from scattered files
  • API Services: Centralize API service imports
  • Constants: Unify constant imports across your project
  • Types: Consolidate TypeScript type imports

⚙️ Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | tsConfigPath | string | "tsconfig.json" | Path to TypeScript configuration file | | sourceGlob | string | "src/**/*.ts{,x}" | Glob pattern to match files for processing | | sourcePath | string | Required | Source folder/path to consolidate imports from | | targetPath | string | Required | Target file path for consolidated imports | | log | boolean | true | Enable logging of processed files |

📝 License

MIT License © [Your Name]


🔧 Requirements

  • Node.js >= 14.0.0
  • TypeScript >= 4.0.0

Made with ❤️ for cleaner TypeScript codebases