Files
Situation-Awareness-Platfor…/src/utils/asset.ts

32 lines
899 B
TypeScript
Raw Normal View History

2025-03-12 18:41:20 +08:00
export const FindFileName = (path: string) => {
/* find filename */
const isName = /.*\/.*\/(.*\..*)/;
const result = isName.exec(path)?.length
? (isName.exec(path) as Array<string>)[1]
: '';
return result.split('.')[0];
};
/** , 使
*
*/
export const TransAssetsUrl = (
source: Record<string, any>,
key: string,
path?: string
): any => {
if (key) {
let target: string | undefined = '';
target = Object.keys(source).find((pathName) => {
const p = path ? `${path}${key}` : key;
return p === FindFileName(pathName);
});
if (target) {
return source[target].default;
} else {
return '';
}
} else {
return '';
}
};