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 🙏

© 2024 – Pkg Stats / Ryan Hefner

import-conductor

v2.6.1

Published

Automatically organize your Typescript import statements

Downloads

3,971

Readme

Logo

All Contributors

import-conductor

Automatically organize your TypeScript imports to keep them clean and readable.

Demo

What it does

Import conductor will order all imports into the following blocks:

1. Block - third party libraries

2. Block - user / company libraries

3. Block - imports from other modules or directories in your codebase

4. Block - imports for the same module

Take a look at the following source file. It's hard to distinguish between third-party imports, company wide imports and files from same module.

import { Component, OnInit } from '@angular/core';
import { CustomerService } from './customer.service';
import { Customer } from './customer.model';
import { Order } from '../order/order.model';
import { LoggerService } from '@myorg/logger';
import { Observable } from 'rxjs';

A cleaner version that is easy scannable would look like this:

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';

import { LoggerService } from '@myorg/logger';

import { Order } from '../order/order.model';

import { Customer } from './customer.model';
import { CustomerService } from './customer.service';

Of course, it's a lot of work to order all import statements in existing code bases. Furthermore, in bigger development teams it's hard to enforce this syntax so that every developer orders their imports accordingly. Especially with AutoImports in IDEs.

That's where import-conductor comes into play. Import-conductor can reorder all imports in your project, and combined with tools like husky you can automatically reorder imports of changed files in a pre commit hook.

Usage

  • Run in the command line:
npx import-conductor -s customer.component.ts -p @myorg
  • Run as a npm script:
 "scripts": {
    "import-conductor": "import-conductor -p @myorg"
 },
  • Integrate with tools like husky:
  "lint-staged": {
    "*.{ts,tsx}": [
      "import-conductor --staged -p @myorg",
      "prettier --write",
      "eslint --fix",
      "git add"
    ]
  },

Options

  • source - Regex to that matches the source files: (defaults to [./src/**/*.ts])
import-conductor --source mySrc/**/*.ts anotherSrc/**/*.ts
import-conductor -s mySrc/**/*.ts anotherSrc/**/*.ts
import-conductor mySrc/**/*.ts anotherSrc/**/*.ts
  • ignore* - Ignore files that match the pattern: (defaults to [])
import-conductor --ignore 'mySrc/**/*some.ts' 'main.ts'
import-conductor -i 'mySrc/**/*some.ts' 'main.ts'

*Note: you can also skip a file by adding the following comment at the top:

// import-conductor-skip
...
  • userLibPrefixes - The prefix of custom user libraries - the prefix used to distinguish between third party libraries and company libs: (defaults to [])
import-conductor --userLibPrefixes @customA @customB
import-conductor -p @customA @customB
  • separator - The string separator between the imports sections: (defaults to \n)
import-conductor --separator '' ==> no separator
  • groupOrder - The group order to follow: (defaults to [thirdParty, userLibrary, differentModule, sameModule])
import-conductor --groupOrder 'userLibrary' 'differentModule' 'sameModule' 'thirdParty'
import-conductor -g 'userLibrary' 'differentModule' 'sameModule' 'thirdParty'
  • staged - Run against staged files: (defaults to false)
import-conductor --staged
  • noAutoMerge - Disable automatically merging 2 import statements from the same source: (defaults to false)
import-conductor --noAutoMerge
  • autoAdd - Automatically adding the committed files when using the staged option: (defaults to false)
import-conductor --autoAdd
import-conductor -a
  • dryRun - Run without applying any changes: (defaults to false)
import-conductor --dryRun
import-conductor -d
  • verbose - Run with detailed log output: (defaults to false)
import-conductor --verbose
import-conductor -v
  • version:
import-conductor --version
  • help:
import-conductor --help
import-conductor -h

Core Team

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!