Skip to content

Latest commit

 

History

History
97 lines (69 loc) · 1.37 KB

CODEMOD.md

File metadata and controls

97 lines (69 loc) · 1.37 KB

Index

Normalize Import Path

Converts relative path of a module reference to a default node_module based path.

Input:

import {a, b, c} from '../../../abc'

Output:

import {a, b, c} from 'abc'

tscodemodrc:

{
  "name": "normalize-import-path",
  "params": {
    // name of the module
    "module": "abc"
  }
}

Shift Imports

Migrates imports from one module to another.

Input:

import {a, b, x, xx} from 'ab'

Output:

import {a, b} from 'ab'
import {x, xx} from 'x'

tscodemodrc:

{
  "name": "shift-imports",
  "params": {

    // name of the source module
    "from": "ab",

    // name of the target module
    "to": "x",

    // all the import specifiers that should be migrated
    "imports": ["x, "xx"]
  }
}

Array To Rest Params

Converts a function call that takes an argument of type Array into a function call where each element of the array is passed as a separate argument.

Input:

myCustomFunction([1, 2, 3])

Output:

myCustomFunction(1, 2, 3)

tscodemodrc:

{
  "name": "array-to-rest-params",
  "params": {
    // name of the function to transform
    "functionName": "myCustomFunction"
  }
}