Skip to content
This repository has been archived by the owner on Dec 4, 2022. It is now read-only.

Command to convert `require` to a static `import`

Notifications You must be signed in to change notification settings

maxlath/vscode-convert-cjs-to-esm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vscode-convert-cjs-to-esm

[2022 update]: vscode now natively offers a refactor to do that, so this extension is unnecessary

A VSCode/VSCodium extension to convert CommonJS require to a ESM static import:

To easily go from:

const suggestionsPerProperties = {
  'wdt:P50': require('./suggestions/wdt_P50'),
  'wdt:P123': require('./suggestions/wdt_P123'),
  'wdt:P629': require('./suggestions/wdt_P629')
}

to:

import wdtP50 from './suggestions/wdt_P50'
import wdtP123 from './suggestions/wdt_P123'
import wdtP629 from './suggestions/wdt_P629'

const suggestionsPerProperties = {
  'wdt:P50': wdtP50,
  'wdt:P123': wdtP123,
  'wdt:P629': wdtP629,
}

one line at a time, by placing the curor on the line to be converted, and executing the command via a keybinding (see below)

Install

cd ~/.vscode/extensions
git clone https://github.com/maxlath/vscode-convert-cjs-to-esm

This command can then be bound to a shortkey, by adding the shortkey to keybindings.json (in my set up, can be found at in ~/.config/VSCodium/User):

{
    "key": "ctrl+alt+i",
    "command": "convert-cjs-to-esm.convert-camel"
},
{
    "key": "ctrl+shift+alt+i",
    "command": "convert-cjs-to-esm.convert-pascal"
}

About

Command to convert `require` to a static `import`

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published