vite_ts_auto/src/utils/file/routeFileUtil.ts

26 lines
814 B
TypeScript
Raw Normal View History

2024-05-08 13:43:24 +08:00
/**
*
* @param filePath
* @param replaceValue
* @returns
*/
export const routeFilenameHelper = (filePath: string) => {
2024-05-08 13:43:24 +08:00
// 匹配文件列表
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 };
2024-05-08 13:43:24 +08:00
}
};