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

classify-imports-extensions

v1.0.1

Published

VScode extensions to classify imports into external, internal, and unknown categories.

Downloads

3

Readme

Classify Imports Extension for Visual Studio Code

The classify-imports extension for Visual Studio Code is designed to organize and categorize import statements within your TypeScript files. It offers various customization options to tailor the sorting and classification according to your preferences.

Features

  • Sorts and organizes import statements.
  • Classifies imports into categories: Third Party Modules, Relative Modules, and Types Modules.
  • Customizable import order to suit your needs.
  • Option to include a blank line between import categories.
  • Ability to sort imports by length.
  • Option to separate type imports into their own category.
  • Option to terminate import statements with a semicolon.
  • Support for adding comments above each import category.

Usage

After installing the extension, access it by executing the classify-imports.sortImports command in the command palette (Cmd+Shift+P).

The extension will automatically arrange and classify your import statements based on the default settings. If you wish to modify these settings, you can do so in your settings.json file.

Default Options

{
  "importOrder": [
    "<THIRD_PARTY_MODULES> --comment THIRD PARTY MODULES",
    "<RELATIVE_MODULES> --comment RELATIVE MODULES",
    "<TYPES_MODULES> --comment TYPES MODULES"
  ],
  "importOrderSeparation": true,
  "importOrderSortByLength": true,
  "importOrderSplitType": true,
  "importWithSemicolon": true,
  "importOrderAddComments": true
}

Customizing Options

To customize the extension's behavior, modify the classify-imports object in your settings.json file. Here's an example:

{
  "classify-imports": {
    "importOrder": [
      "<RELATIVE_MODULES> --comment RELATIVE MODULES",
      "<THIRD_PARTY_MODULES> --comment THIRD PARTY MODULES",
      "<TYPES_MODULES> --comment TYPES MODULES"
    ],
    "importOrderSeparation": true,
    "importOrderSortByLength": true,
    "importOrderSplitType": true,
    "importWithSemicolon": false,
    "importOrderAddComments": true
  }
}

Example

import { Component } from '@angular/core';
import { Observable } from 'rxjs';
import { User } from '../models/user.model';
import { UserService } from '../services/user.service';
import type { UserInterface } from '../types/user.interface';

=> After running the classify-imports.sortImports command, the import statements will be sorted and categorized as follows:

// RELATIVE MODULES
import { User } from '../models/user.model';
import { UserService } from '../services/user.service';

// THIRD PARTY MODULES
import { Observable } from 'rxjs';
import { Component } from '@angular/core';

// TYPES MODULES
import type { UserInterface } from '../types/user.interface';

In this example, the import order has been reversed, and all other options have been disabled (false).

Explanation of Options

  • importOrder: Defines the order in which import statements will be sorted and categorized. Imports are classified into Third Party Modules, Relative Modules, and Types Modules. The order of categories in the array determines their sequence in the sorted import statements. The --comment flag adds a descriptive comment above each category.

  • importOrderSeparation: Inserts a blank line between each category of import statements if set to true.

  • importOrderSortByLength: Sorts import statements within each category based on their length if set to true.

  • importOrderSplitType: Separates type imports into a dedicated category (Types Modules) if true; otherwise, includes type imports within their respective categories (Third Party or Relative).

  • importWithSemicolon: Appends a semicolon to the end of each import statement if true.

  • importOrderAddComments: Includes comments above each category of import statements as specified in importOrder.

Note

This extension exclusively supports ES6 (import syntax) TypeScript files and does not function with CommonJS (require syntax) files.