@bleed-believer/path-alias
Version:
Assign path alias using tsconfig.json file
27 lines (26 loc) • 598 B
JavaScript
export class ExtParser {
#input;
constructor(input){
this.#input = input;
}
isFileUrl() {
try {
const url = new URL(this.#input);
return url.protocol === 'file:';
} catch {
return false;
}
}
isTs() {
return !!this.#input.match(/(\.m?tsx?)$/gi);
}
isJs() {
return !!this.#input.match(/(\.m?jsx?)$/gi);
}
toTs() {
return this.#input.replace(/(?<=\.m?)j(?=(sx?)$)/gi, 't');
}
toJs() {
return this.#input.replace(/(?<=\.m?)t(?=(sx?)$)/gi, 'j');
}
}