Change Parameter Object
Modify the function argument to take an object.
- before
- after
import { dummyFunction } from "foo";
dummyFunction("hello", "this is dashboard page");
import { dummyFunction } from "foo";
dummyFunction({
"title": "hello",
"description": "this is dashboard page"
});
Options
type Options = {
functionSourceType?: "absolute" | "relative";
functionNameType?: "default" | "named";
functionSource: string;
functionName: string;
objectKeys: string[];
};
- functionSourceType: componentSource's type. you can choose absolute or relative
- functionNameType: changed target specifier
- functionSource: component source. you can choose package name or target path
- functionName: props to add's component name
- objectKeys: add props's name
Usage
The usage method differs depending on the source type of the import statement to be converted.
absolute
This is a situation where the source of the import module you want to change is an absolute path.
option.ts
const option = {
functionSourceType: "absolute",
functionNameType: "named",
functionSource: "foo",
functionName: "dummyFunction",
objectKeys: ["title", "description"],
};
- before
- after
import { dummyFunction } from "foo";
dummyFunction("hello", "this is dashboard page");
import { dummyFunction } from "foo";
dummyFunction({
"title": "hello",
"description": "this is dashboard page"
});
relative
This is a situation where the source of the import module you want to change is an absolute path.
option.ts
const option = {
functionSourceType: "relative",
functionNameType: "named",
functionSource: path.join(process.cwd(), "../test/foo.ts"),,
functionName: "dummyFunction",
objectKeys: ["title", "description"],
};
- before
- after
import { dummyFunction } from "../test/foo.ts";
dummyFunction("hello", "this is dashboard page");
import { dummyFunction } from "../test/foo.ts";
dummyFunction({
"title": "hello",
"description": "this is dashboard page"
});