26 lines
814 B
TypeScript
26 lines
814 B
TypeScript
/**
|
|
* 文件名工具方法
|
|
* @param filePath 文件路径
|
|
* @param replaceValue 替换
|
|
* @returns 文件转换对象
|
|
*/
|
|
export const routeFilenameHelper = (filePath: string) => {
|
|
// 匹配文件列表
|
|
const fileMatchList = filePath.match(/\/([^/]+)$/);
|
|
|
|
// 列表不为空
|
|
if (fileMatchList !== null) {
|
|
// 文件+扩展名
|
|
const fileExtension = fileMatchList[1];
|
|
// 文件名
|
|
const filename = fileMatchList[1].replace(/\.\w+$/g, '');
|
|
// 路径名带文件名
|
|
const fullPath = `/${filePath.replace(/\/src\/views\/|(\.\w+)?$/g, '')}`;
|
|
// 路径下划线名
|
|
const name = fullPath.replace(/\/(index|page)|^\//g, '').replace(/\//g, '_');
|
|
// 路径名不带文件名
|
|
const path = fullPath.replace(/\/[^/]*$/, '');
|
|
return { fileExtension, filename, name, fullPath, path, filePath };
|
|
}
|
|
};
|