import type { TriggerDefinition } from "../types" const NAMESPACE_DISPLAY_NAMES: Partial> = { github: "GitHub", whatsapp: "WhatsApp", } /** * Resolves a definition's display name without loading the global catalog. * * @param definition - Trigger definition to name. */ export function getTriggerDefinitionName(definition: TriggerDefinition) { if (definition.name) return definition.name const [namespace = definition.type] = definition.type.split(".") const inferredName = sentenceCase(definition.type) const namespaceDisplayName = NAMESPACE_DISPLAY_NAMES[namespace] return namespaceDisplayName ? inferredName.replace(sentenceCase(namespace), namespaceDisplayName) : inferredName } /** * Converts a stable identifier to a sentence-cased display name. * * @param value - Stable identifier to format. */ export function sentenceCase(value: string) { const words = value .replaceAll(/([a-z\d])([A-Z])/g, "$1 $2") .replaceAll(/[._-]+/g, " ") .toLowerCase() return words.charAt(0).toUpperCase() + words.slice(1) }