27 lines
629 B
TypeScript
27 lines
629 B
TypeScript
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;
|
|
}
|
|
}
|