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

js-isort

v3.5.0

Published

Group and sort JS imports.

Downloads

639

Readme

js-isort

js-isort is a command line tool for grouping, sorting and deduping ES2015 imports.

The following transformations take place:

  1. Groups imports by module specificity (e.g. built-in vs. external vs. internal)
  2. Collapses imports defined on multiple lines into one line
  3. Sorts imports alphabetically within groups (uses natural sort order)
  4. Sorts import specifiers alphabetically (uses natural sort order)
  5. Separates groups with an empty line

Usage

Usage: js-isort [options] <file ...>

Options:

  -v, --version          output the version number
  --config-path [value]  Path to Babel or Webpack config file containing aliases
  -h, --help             output usage information

Grouping

// 1. Side effects (NOT sorted alphabetically because order may matter)
import './global-styles.css';
import 'babel-polyfill';

// 2. Node.js builtin modules
import fs from 'fs';
import http from 'http';

// 3. External modules
import classNames from 'classnames';
import React from 'react';

// 4. Aliases (from Webpack or Babel)
import App from 'components/App';
import format from 'utils/format';

// 5. Relative parent modules (sorted by depth)
import middleware from '../../middleware';
import getUserId from '../getUserId';

// 6. Relative sibling modules
import queries from './queries';
import styles from './styles';

// 7. Imports from the index.js file
import main from './';

Deduplication

If you have this:

import { Mutation } from 'react-apollo';
import { ApolloProvider } from 'react-apollo';
import ReactApollo from 'react-apollo';

You will get this:

import ReactApollo, { ApolloProvider, Mutation } from 'react-apollo';

Specifiers

If you have this:

import foo1, { foo1000, foo200, foo30, foo4, bar } from 'foo';

You will get this:

import foo1, { bar, foo4, foo30, foo200, foo1000 } from 'foo';

Aliases

In order for aliases to be recognized, you must pass in the path to your Webpack or Babel config file:

js-isort-cli --config-path webpack.config.js myFile.js

Note: it can be expensive to import the config, so js-isort will cache the aliases in a temporary file. The cache is invalidated when the config file is updated.

Comments

Comments at the top of the file will stay in place. All other comments will move with the associated import.

JS Syntax SUpport

js-isort uses Babel under the hood, with a couple Stage 3 language features and support for JSX enabled.

Configuration

js-isort is not currently configurable. Maybe one day.

License

See LICENSE.