Skip to content

Instantly share code, notes, and snippets.

@thiagosf
Last active August 4, 2021 14:58
Show Gist options
  • Save thiagosf/a74e58fa6e275f69f2d4372d42024298 to your computer and use it in GitHub Desktop.
Save thiagosf/a74e58fa6e275f69f2d4372d42024298 to your computer and use it in GitHub Desktop.
JavaScript to TypeScript Migration

JavaScript to TypeScript Migration

Replaces:

^const ([^ ]+) = require\(([^)]*)\)$
import $1 from $2

^const ([^ ]+) = require\(([^)]*)\).(.*)$
import { $3 as $1 } from $2

^const \{ ([^}]+)\} = require\(([^)]*)\)$
import { $1 } from $2

module\.exports =
export default

Renaming .js to .ts (it takes a while):

find . -depth -name "*.js" -exec sh -c 'mv "$1" "${1%.js}.ts"' _ {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment