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

@tsimports/tsimports

v0.1.4

Published

A fast and opinionated imports organizer for ECMAScript and TypeScript.

Downloads

229

Readme

tsimports

✨ A fast and opinionated imports organizer for ECMAScript and TypeScript.

[!WARNING] This project is in alpha stage. Do not use in production.

Installation

npm install -g tsimports

[!TIP] If you want to manage the version of tsimports, use -D instead of -g.

Usage

Basic

Format a file and write the result to stdout

tsimports ./src/foo.ts

Format a file and write in-place

tsimports --write ./src/foo.ts

Format all TypeScript files

tsimports --write ./src/**/*.ts

Advanced

Format a stdin input

[!WARNING] tsimports infers the language from the file extension. As the standard input has no extension, we cannot infer the language. Use --language to assume the input is JS, JSX, TS, or TSX.

cat ./src/foo.ts | tsimports --language ts

The rule

tsimports groups and sorts import statements in the file in a fixed rule. As tsimports offers you an opinionated rule, you cannot configure any of the rule.

Groups

tsimports splits the imports into several groups in the following order:

  1. Built-in modules (e.g. node:assert, fs, or bun)
  2. External modules (e.g. react, @testing-library/react, or hono/jwt)
  3. Internal modules (e.g. ~/foo or @/foo, if configured in bundler or somewhere)
  4. Parent modules (e.g. ../foo or ../../foo)
  5. Sibling modules (e.g. ./foo or ./foo/bar)
  6. Index modules (e.g. ., ./, ./index, or ./index.js)

Ordering

tsimports sorts imports in each group in alphabetical order (case-sensitive).

Position

tsimports collects all imports at the top of the file. Any other statements are retained at the position and tsimports doesn't modify anything about them.

Acknowledgements

tsimports is built on top of the Biome infrastructure, including the JS syntax, parser, and other utils. If you like tsimports, please consider also supporting the Biome project.