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

react-import-sorter

v1.1.0

Published

Opinionated import sorter for React apps

Readme

react-import-sorter

Opinionated import sorter for React and Next.js codebases.

This package rewrites the import section of a file into predictable, readable blocks with blank lines between groups. It is built for teams that want a consistent import style similar to isort-style grouping in Python projects.

Why use this

  • Keeps imports consistently grouped and alphabetized
  • Puts framework imports first
  • Separates React and Next imports into distinct blocks
  • Splits icon libraries, internal API imports, context imports, and type imports into dedicated sections
  • Works as a CLI and as a programmatic function

Install

Global

npm i -g react-import-sorter

Project dependency

npm i -D react-import-sorter

CLI usage

react-import-sorter <file>

Example:

react-import-sorter src/App.tsx

If the provided path does not exist but exactly one file with the same basename is found in the project, the CLI will use that file and print a warning.

CLI options

Customize framework priority

react-import-sorter src/App.tsx --framework-priority=next,react,react-dom

This controls the order used for framework imports inside framework-related groups.

Help

react-import-sorter --help

Import grouping behavior

Imports are emitted in this high-level order:

  1. Framework imports (with sub-groups)
    • React family: react, react-dom, react-router, react-router-dom
    • Next family: next and next/*
    • Other supported frameworks (gatsby, vue, nuxt, svelte, solid-js, @angular/, @remix-run/)
  2. Third-party libraries
  3. Icon libraries (lucide-react, react-icons, @heroicons/*)
  4. Internal type imports (import type and paths containing /types/)
  5. Internal API imports (@/api/*)
  6. Internal context imports (@/app/contexts/*)
  7. Other internal absolute imports (@/*)
  8. Relative imports (./, ../)
  9. Any remaining unmatched imports

Rules inside each group:

  • Alphabetical by import source path
  • One blank line between groups

Example

Input:

import React from 'react'
import type { Metadata } from 'next'
import Link from 'next/link'
import Swal from 'sweetalert2'
import 'sweetalert2/dist/sweetalert2.min.css'
import { Download } from 'lucide-react'
import { usePatient } from '@/app/contexts/PatientContext'
import { submitPARequest } from '@/api/pa-requests'
import type { PARequestPayload } from '@/types/paRequest'
import Button from '@/app/components/button'
import LocalThing from './LocalThing'

Output:

import React from 'react'

import type { Metadata } from 'next'
import Link from 'next/link'

import Swal from 'sweetalert2'
import 'sweetalert2/dist/sweetalert2.min.css'

import { Download } from 'lucide-react'

import type { PARequestPayload } from '@/types/paRequest'

import { submitPARequest } from '@/api/pa-requests'

import { usePatient } from '@/app/contexts/PatientContext'

import Button from '@/app/components/button'

import LocalThing from './LocalThing'

Programmatic API

import { sortImports } from 'react-import-sorter'

const sorted = sortImports(sourceCode, {
  frameworkPriority: ['next', 'react', 'react-dom']
})

Type:

type SortImportsOptions = {
  frameworkPriority?: string[]
}

Development

npm run build
node dist/bin/cli.js App.tsx

License

MIT