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

@getsupervisor/js-sort-imports

v1.0.1

Published

Ordenador de imports/exports de TypeScript compatible con Prettier: agrupa terceros vs. alias internos (leídos del tsconfig), ordena por binding y respeta printWidth/trailingComma para no chocar con Prettier.

Readme

@getsupervisor/js-sort-imports

Ordenador de imports/exports de TypeScript (.ts / .tsx) compatible con Prettier.

Reordena y agrupa tus imports/exports de forma determinista y sin pelearse con Prettier: lee la config de Prettier de tu proyecto (printWidth, trailingComma, tabWidth) y produce exactamente el mismo formato, de modo que sort-imports + prettier convergen al mismo resultado y --check nunca da falsos positivos.

npm license: MIT

Por qué

La mayoría de ordenadores de imports formatean a su manera y entran en conflicto con Prettier (comillas, ancho de línea, la directiva 'use client', el wrapping de los { … }). Este tool:

  • No choca con Prettier — toma printWidth/trailingComma/tabWidth de tu config y parte los { … } largos a multilínea igual que Prettier; deja 'use client' en su propia línea.
  • Resuelve los alias de tu tsconfig para distinguir "terceros" de "código interno".
  • Cero configuración en el caso común: detecta tsconfig.json y la config de Prettier solos.

Instalación

npm install -D @getsupervisor/js-sort-imports

Requiere Node ≥ 18. Incluye typescript como dependencia (no necesitas tenerlo aparte).

Uso (CLI)

# Reordena y escribe en disco
npx sort-imports "src/**/*.{ts,tsx}"

# Solo verifica — exit 1 si algo está sin ordenar (útil en CI / pre-commit)
npx sort-imports --check "src/**/*.{ts,tsx}"

# Un archivo o una carpeta
npx sort-imports src/components/Button/Button.tsx
npx sort-imports src

Como script en package.json:

{
  "scripts": {
    "sort": "sort-imports --write \"src/**/*.{ts,tsx}\"",
    "sort:check": "sort-imports --check \"src/**/*.{ts,tsx}\""
  }
}

Opciones

| Opción | Descripción | Default | | ---------------------- | ---------------------------------------------------------------------- | ----------------------------- | | --check | Solo verifica; exit 1 si hay cambios pendientes (no escribe) | — | | --write | Escribe los cambios en disco | (por defecto) | | --tsconfig <path> | tsconfig para resolver alias | ./tsconfig.json | | --print-width <n> | Ancho antes de partir un import a multilínea | config de Prettier, o 80 | | --trailing-comma <v> | all | es5 | none para el bloque multilínea | config de Prettier, o all | | -h, --help | Ayuda | — |

Cómo ordena

  1. Dos grupos, separados por una línea en blanco: primero terceros, luego internos (relativos ./… y los alias de tsconfig como @/…).
  2. Dentro de cada grupo, por tipo: side-effect → * as nsdefaultimport type → named ({ … }).
  3. Dentro de cada tipo, alfabético por el binding (nombre importado, no por la ruta).
  4. Los especificadores dentro de { … } también se ordenan alfabéticamente.
  5. Aplica lo mismo a los export … from.

Ejemplo:

// antes
import { useState } from 'react';
import Button from '@/components/Button';
'use client';
import { z } from 'zod';

// después
'use client';
import { useState } from 'react';
import { z } from 'zod';

import Button from '@/components/Button';

Junto a Prettier (recomendado)

Corre el orden antes de Prettier; como ambos comparten la config, el resultado es idéntico:

sort-imports --write "$FILE" && prettier --write "$FILE"

Funciona muy bien en un hook de pre-commit (lint-staged) o en un hook post-edición de tu editor/agente.

API programática

const { sortImportsInContent, sortImportsInFile } = require('@getsupervisor/js-sort-imports');

// Sobre un string
const { content, changed } = sortImportsInContent(sourceText, 'Foo.tsx');

// Sobre un archivo (write opcional)
const result = sortImportsInFile('src/Foo.tsx', { write: true });

Licencia

MIT © getsupervisor