- normalize-import-path
- shift-imports
- array-to-rest-params
- convert-to-call
- migrate-modules
- replace-node
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
{
transformation: 'normalize-import-path',
params: {
// name of the module
module: 'abc'
}
}
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
{
transformation: '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']
}
}
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
{
transformation: 'array-to-rest-params',
params: {
// name of the function to transform
functiontransformation: 'myCustomFunction'
}
}
Converts a value to a function call.
Input:
const result = abc
Output:
const result = abc()
.tscodemodrc
{
transformation: 'convert-to-call',
params: {
// name of the identifier
name: 'abc'
}
}
Migrates module specifier
Input:
import abc from 'abc'
Output:
import abc from 'abc-abc' // renamed the module specifier
.tscodemodrc
{
transformation: 'migrate-modules',
params: {
modules: {
// module map
abc: 'abc-abc'
}
}
}
Replaces a ts.Node
with another one. It is kind of like search and replace but much more powerful.
It ignores whitespaces and works directly on the AST.
Input:
const abc = a(b(c))
Output:
const abc0 = K(a, b)(c)
.tscodemodrc
{
transformation: 'replace-node',
params: {
matchWith: 'a(b(c))',
replaceWith: 'K(a, b)(c)'
}
}