Skip to content
cptpiepmatzPublic

About

✨ Pretty imports, your rules. A small, extensible toolkit for sorting and formatting JavaScript and TypeScript imports across frameworks and file formats.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

289 Commits

Folders and files

Repository files navigation

primp logo

primp

✨ Pretty imports, your rules.


JSR Deno Node.js License CI

About

primp is an import formatter for TypeScript, with optional JavaScript and Vue support. It parses imports using the TypeScript parser, sorts them with a chain of rules, and groups them with blank lines. You can use the defaults or define exactly how your imports should look.

The formatter works on the leading import block and leaves the rest of your code intact. Use it from the command line or as a library in your own tooling.

Features

  • Your own import order: Combine built-in comparators, reverse them, or write custom functions in a TypeScript config.
  • Separate sorting and grouping: Decide both where imports belong and where blank lines go.
  • Consistent formatting: Sort named specifiers and configure quotes, indentation, and line wrapping. Defaults work with deno fmt.
  • Modern syntax: Preserve type-only imports, inline type specifiers, and import attributes.
  • CLI workflow: Process several paths, recurse through directories, watch files, or check formatting in CI.
  • Extensible file support: Register extractors for JavaScript, Vue SFCs, or your own source format.

Packages

Package What it provides
@primp/primp Import formatter, CLI, configuration, and built-in rules.
@primp/vue An extractor for imports inside Vue <script> and <script setup> blocks.

The core package does not depend on Vue. Add the adapter when you need to format single-file components.

Installation

Primp supports Deno 2+ and Node.js 22.18+. Packages are available on JSR.

# Deno
deno add jsr:@primp/primp

# Node.js, through JSR's npm compatibility bridge
npx jsr add --npm @primp/primp

To make primp available as a global command, install the CLI with Deno:

deno install --global --allow-read --allow-write --allow-env --name primp jsr:@primp/primp/cli

Usage

# Format a directory recursively
primp src -r

# Format several files or directories
primp src tests index.ts -r

# Check formatting without writing files
primp src -r --check

You can also run the CLI directly:

# Deno
deno run --allow-read --allow-write --allow-env jsr:@primp/primp/cli src -r

# Node.js, after installing the package through JSR
node node_modules/@primp/primp/cli.js src -r

Create a primp.config.ts to customize the rules:

import { defineConfig } from "jsr:@primp/primp";
import { sourceName } from "jsr:@primp/primp/rules/imports";

export default defineConfig({
  sortImports: [sourceName],
  formatting: { quoteStyle: "single" },
});

For library use, pass source text to formatImports:

import { formatImports } from "jsr:@primp/primp";

const formatted = formatImports('import { b, a } from "pkg";\n');
// import { a, b } from "pkg";

In Node projects, use "@primp/primp" and its corresponding subpaths instead of "jsr:@primp/primp". See the core package guide for CLI flags and configuration, or the Vue guide to add SFC support.

Testing

With Deno 2+ and Node.js 22.18+ installed, run:

deno install
deno task check
deno task lint
deno task test

deno task test runs both the Deno suite and Node smoke tests. You can run them separately with deno task test:deno and deno task test:node. Use deno task fmt to format the workspace and its imports, and deno fmt --check to check source formatting.

License

primp is released under the MIT License.

About

✨ Pretty imports, your rules. A small, extensible toolkit for sorting and formatting JavaScript and TypeScript imports across frameworks and file formats.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages