Me (Amit)

AMWAM - Amit Shah

Agile Software Developer, based in London.

Sorting Javascript imports

17/07/2016

javascript

I've published my first NPM package js-import-sort! Its a JS tool to sort and organise ES2015/ES6 imports. You can find it on GitHub.

It was created using a tool from facebook called jscodeshift, which is a library for building javascript codemods.

Example:

import Main from 'aaaa';
import {ZMain}  from 'aaaa';
   

import First from 'zzz';
import {Third} from 'zzz';


import {Second} from 'zzz';


import * as someDefault from 'bbb';


import {a as b} from 'packageModule';


import SomeClass from './MyModule';
import AnotherClass from '../../Module1';


import * as util from 'util';

Becomes:

import * as util from 'util';

import Main, {ZMain} from 'aaaa';
import * as someDefault from 'bbb';
import First, {Second, Third} from 'zzz';

import {a as b} from 'packageModule';

import AnotherClass from '../../Module1';
import SomeClass from './MyModule';

Imports are separated by node, dependencies in package.json, other and relative imports.