Skip to main content

Seperate Named Specifier

Change the specifier of the import module and the identifier that uses it. but local variable is not converted. only convert global value

import { calculateSum, calculateSubtract } from "utils";

Options

type Options {
specifiers: string[];
fromSource: string;
toSource: string;
sourceType?: "relative" | "absolute";
}
  • specifiers: seperate named specifier's specifiers
  • fromSource: seperate named specifier's source
  • toSource: seperate named specifier's target source
  • sourceType: seperate named specifier's source's type. you can choose absolute or relative

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 = {
specifiers: ["calculateSum"],
sourceType: "absolute",
fromSource: "utils",
toSource: "lib",
};
import { calculateSum } from "utils";

relative

This is a situation where the source of the import module you want to change is an absolute path.

option.ts
const option = {
sourceType: "relative",
specifiers: ["calculateSum"],
fromSource: path.join(process.cwd(), "../test/utils.ts"),
toSource: path.join(process.cwd(), "../lib.ts"),
};
import { sum } from  "./utils.ts"

console.log(sum())