ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Sort Java​Script Imports

by insin ALL

Sublime Text package for sorting selected JavaScript import/require() lines by module name

Details

Installs

  • Total 3K
  • Win 2K
  • Mac 909
  • Linux 515
Apr 25 Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11
Windows 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1
Mac 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
Linux 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0

Readme

Source
raw.​githubusercontent.​com

Sort JavaScript Imports

Adds a Sort JavaScript Imports command to Sublime Text 2 or 3, which sorts selected lines containing JavaScript import statements or require() calls by the module path they're importing.

Install via Package Control

Ctrl-Shift-P/Command-Shift-P → Package Control: Install Package → Sort JavaScript Imports

Install via git clone

Preferences → Browse Packages… → git clone https://github.com/insin/sublime-sort-javascript-imports.git "Sort JavaScript Imports"

Usage

Select lines containing the import statements you want to sort, then use either of:

  • Command palette: Ctrl-Shift-P/Command-Shift-P → Sort JavaScript Imports
  • Default key binding: Alt-F9 on Linux/Windows or Alt-F5 on Mac

Lines will be sorted based on the module path being imported, respecting (and normalising) any blank lines used to divide imports into different categories.

Any non-import lines in the selection will be moved to the end, separated by a new blank line if necessary. Let me know if there's a preferable way to handle these.

Import ordering

Where top-level imports and path-based imports are mixed in the same block, they will be ordered as follows:

  1. Top-level imports
  2. Imports which traverse up out of the current directory, from furthest away to closest
  3. Imports within the current directory

Note: if you're using Webpack aliases or a Babel alises plugin for top-level importing of your app's own code, you might want to put those in a separate block for clarity.

Example

MIT Licensed

Unit testing and configuration setup cribbed from Sort Lines (Numerically).