A CLI and library to format JavaScript/TypeScript import/export statements with grouping, sorting, deduplication, and unused import removal. Current stable version is 4.0.8, released with support for Import Attributes, ArkTS, and async config resolution. Unlike similar tools (e.g., eslint-plugin-import), it works as a standalone formatter with ESLint, Prettier, and EditorConfig compatibility, and can be used in CI/CD or integrated into IDEs via its VSCode and IntelliJ plugins. Actively maintained with monthly releases.
npm install format-importsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates reading a TypeScript file, resolving configuration, formatting imports, and writing the formatted output back.
Use await when calling resolveConfigForFile, or handle the returned Promise.
Use import statements or set type: 'module' in package.json.
Use -o or --output as before, but the old --output with equals sign may stop working in future.
Provide a dummy file path via --config if needed, or pass options directly via API.
Install typescript in your project if you use type-only imports/exports.
Run 'npm install -D format-imports' and ensure using import instead of require().
Use `import { resolveConfigForFile } from 'format-imports'` and verify package version >=4.0.0.Ensure the file is valid JavaScript/TypeScript; format-imports expects module files.
Create a configuration file, or use the API with explicit options.