feat: import resource

This commit is contained in:
Ahmed Bouhuolia
2024-03-14 22:18:12 +02:00
parent daa1e3a6bd
commit 084d9d3d10
14 changed files with 360 additions and 352 deletions

View File

@@ -0,0 +1,31 @@
import { camelCase, upperFirst } from 'lodash';
export class ImportableRegistry {
private static instance: ImportableRegistry;
private importables: Record<string, any>;
private constructor() {
this.importables = {};
}
public static getInstance(): ImportableRegistry {
if (!ImportableRegistry.instance) {
ImportableRegistry.instance = new ImportableRegistry();
}
return ImportableRegistry.instance;
}
public registerImportable(resource: string, importable: any): void {
const _resource = this.sanitizeResourceName(resource);
this.importables[_resource] = importable;
}
public getImportable(name: string): any {
const _name = this.sanitizeResourceName(name);
return this.importables[_name];
}
private sanitizeResourceName(resource: string) {
return upperFirst(camelCase(resource));
}
}