On npmjs.com, libraries often provide code snippets that start like
var md5 = require('md5');
but this syntax is like a million years old. I usually copy and paste the code and transform it to
import md5 from 'md5';
ES2016 style. Is there a shortcut in WebStorm / IntelliJ to do this automatically? Or any other way to not having to do this manually?
Starting from IntelliJ 2016.3 you can automatically convert require
to import
.
See the following youtube demo.
This is also described on the JetBrains blog:
ECMAScript 6. IntelliJ IDEA now reports all var declarations and helps replace them with let or const declarations, depending on recognized value semantics. For all require() calls, the IDE now provides a quick-fix that replaces them with import statements. For function calls and prototype chains, the IDE provides a quick-fix that replaces them with class statements. Other improvements include better support for destructuring assignments, and default exports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With