mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
20 lines
613 B
TypeScript
20 lines
613 B
TypeScript
export function sanitizeModuleName(moduleName: string, removeExtension: boolean = true): string {
|
|
moduleName = moduleName.trim();
|
|
|
|
if (moduleName.startsWith("~/")) {
|
|
moduleName = moduleName.substring(2);
|
|
} else if (moduleName.startsWith("~")) {
|
|
moduleName = moduleName.substring(1);
|
|
} else if (moduleName.startsWith("/")) {
|
|
moduleName = moduleName.substring(1);
|
|
}
|
|
|
|
if (removeExtension) {
|
|
const lastDot = moduleName.lastIndexOf(".");
|
|
if (lastDot > 0) {
|
|
moduleName = moduleName.substr(0, lastDot);
|
|
}
|
|
}
|
|
|
|
return moduleName;
|
|
} |