Initial project
This commit is contained in:
26
src/utils/IconMapper.ts
Normal file
26
src/utils/IconMapper.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import iconJson from "../assets/icon.json";
|
||||
|
||||
export default class IconMapper {
|
||||
|
||||
private static instance: IconMapper;
|
||||
|
||||
icons = new Map<string, string>();
|
||||
|
||||
private constructor() {
|
||||
Object.entries(iconJson).forEach(([key, value]) => this.icons.set(key, value));
|
||||
}
|
||||
|
||||
public getSVG(name: string, scale = 1) {
|
||||
const svg = IconMapper.getInstance().icons.get(name.toLowerCase());
|
||||
return svg?.replace(/\d+(\.\d+)?/gm, n => {
|
||||
return String((Number(n) * scale));
|
||||
});
|
||||
}
|
||||
|
||||
public static getInstance(): IconMapper {
|
||||
if (!IconMapper.instance) {
|
||||
IconMapper.instance = new IconMapper();
|
||||
}
|
||||
return IconMapper.instance;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user