Advertisement
djbob2000

Untitled

Jan 16th, 2025
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //src/fd/fd-toolbox/converters/resource-name-converter.ts
  2. import { errorMessages } from "@/meta/constants/error-messages";
  3. import { createError } from "@/fd/fd-toolbox/errors/errors";
  4. import { resourceIds } from "../constants/resource-id";
  5. import { WithIndexer } from "../types/with-indexer";
  6.  
  7. const resourceMetaIds: WithIndexer<string> = {};
  8.  
  9. export function getResourceMetaId(resourceName: string) {
  10.     return resourceMetaIds[resourceName.toLowerCase()];
  11. }
  12.  
  13. export function setResourceMetaId(resourceName: string, resourceMetaId: string) {
  14.     const key = resourceName.toLowerCase();
  15.  
  16.     if (!resourceMetaIds[key]) {
  17.         resourceMetaIds[key] = resourceMetaId;
  18.     }
  19. }
  20.  
  21. export function getResourceNameFromResourceMetaId(resourceMetaId: string): string {
  22.     const resourceName = Object.entries(resourceMetaIds).find(([_, id]) => id === resourceMetaId)?.[0];
  23.  
  24.     if (resourceName) {
  25.         return resourceName;
  26.     }
  27.  
  28.     throw createError(errorMessages.resourceMetaIdNotConverted.replace("{0}", resourceMetaId));
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement