Skip to content

Instantly share code, notes, and snippets.

View piyush2206's full-sized avatar

Piyush Vishwakarma piyush2206

  • Fynd
  • Mumbai
View GitHub Profile
@benoitv-code
benoitv-code / require-to-import.js
Last active September 27, 2022 07:32
Automatically converts `require` to `import` syntax (Node.js ES5 to TypeScript / ES6)
#!/usr/bin/env node
// from https://github.com/jameswomack/replace-require-with-import/blob/master/index.js
// changes: support importing files with a `@` in their names, support require with multiple keys `{ funcA, funcB }`
// usage: `node ./require-to-import.js ./src/**/*.ts`
const FS = require('fs')
const globby = require('globby')
const r1 = /^(let|var|const) +([a-zA-Z_$][a-zA-Z0-9_$]*) +\= +(require)\((('|")[@a-zA-Z0-9-_.\/]+('|"))\)/gm // const createStore = require('redux')