resolveFromCatalog function

Last updated: 2026-03-01T23:25:47.122Z

Metrics

LOC: 41 Complexity: 14 Params: 3

Signature

resolveFromCatalog( key: string, substitutions?: string | string[], ): : string | null

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'resolveFromCatalog' has cyclomatic complexity 14 (max 10)

Source Code

function resolveFromCatalog(
  key: string,
  substitutions?: string | string[],
): string | null {
  if (!_catalog) return null;
  const entry = _catalog[key];
  if (!entry) return null;

  let msg = entry.message;
  const subs = substitutions
    ? Array.isArray(substitutions)
      ? substitutions
      : [substitutions]
    : [];

  if (subs.length > 0) {
    if (entry.placeholders) {
      // Named placeholder format: $name$ resolved via placeholders map
      const resolved: Record<string, string> = {};
      for (const [name, { content }] of Object.entries(entry.placeholders)) {
        const match = content.match(/^\$(\d+)$/);
        if (match) {
          const idx = parseInt(match[1], 10) - 1;
          if (idx < subs.length) resolved[name.toLowerCase()] = subs[idx];
        }
      }
      msg = msg.replace(
        /\$(\w+)\$/g,
        (_, name: string) => resolved[name.toLowerCase()] ?? `$${name}$`,
      );
    } else {
      // Simple positional format: $1, $2, …
      msg = msg.replace(/\$(\d+)/g, (_, n: string) => {
        const idx = parseInt(n, 10) - 1;
        return idx < subs.length ? subs[idx] : `$${n}`;
      });
    }
  }

  return msg || null;
}

No outgoing dependencies.

Impact (Incoming)

graph LR resolveFromCatalog["resolveFromCatalog"] t["t"] t -->|calls| resolveFromCatalog style resolveFromCatalog fill:#dbeafe,stroke:#2563eb,stroke-width:2px click resolveFromCatalog "d12ced3ca7ceb564.html" click t "9d896dd480f7cc17.html"
SourceType
t calls