Sort JavaScript Imports
Sublime Text package for sorting selected JavaScript import/require() lines by module name
Details
Installs
- Total 3K
- Win 2K
- Mac 926
- Linux 531
Oct 14 | Oct 13 | Oct 12 | Oct 11 | Oct 10 | Oct 9 | Oct 8 | Oct 7 | Oct 6 | Oct 5 | Oct 4 | Oct 3 | Oct 2 | Oct 1 | Sep 30 | Sep 29 | Sep 28 | Sep 27 | Sep 26 | Sep 25 | Sep 24 | Sep 23 | Sep 22 | Sep 21 | Sep 20 | Sep 19 | Sep 18 | Sep 17 | Sep 16 | Sep 15 | Sep 14 | Sep 13 | Sep 12 | Sep 11 | Sep 10 | Sep 9 | Sep 8 | Sep 7 | Sep 6 | Sep 5 | Sep 4 | Sep 3 | Sep 2 | Sep 1 | Aug 31 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Windows | 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 | 0 | 0 | 0 | 0 |
Mac | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Linux | 0 | 0 | 0 | 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 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 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 orAlt-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:
- Top-level imports
- Imports which traverse up out of the current directory, from furthest away to closest
- 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).