Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //src/fd/fd-toolbox/converters/resource-name-converter.ts
- import { errorMessages } from "@/meta/constants/error-messages";
- import { createError } from "@/fd/fd-toolbox/errors/errors";
- import { resourceIds } from "../constants/resource-id";
- import { WithIndexer } from "../types/with-indexer";
- const resourceMetaIds: WithIndexer<string> = {};
- export function getResourceMetaId(resourceName: string) {
- return resourceMetaIds[resourceName.toLowerCase()];
- }
- export function setResourceMetaId(resourceName: string, resourceMetaId: string) {
- const key = resourceName.toLowerCase();
- if (!resourceMetaIds[key]) {
- resourceMetaIds[key] = resourceMetaId;
- }
- }
- export function getResourceNameFromResourceMetaId(resourceMetaId: string): string {
- const resourceName = Object.entries(resourceMetaIds).find(([_, id]) => id === resourceMetaId)?.[0];
- if (resourceName) {
- return resourceName;
- }
- throw createError(errorMessages.resourceMetaIdNotConverted.replace("{0}", resourceMetaId));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement