All files / src/app/graph/_lib graph-text.ts

100% Statements 8/8
100% Branches 4/4
100% Functions 2/2
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                      4x       20655x 15239x 15239x 5416x 5416x   15239x    
/**
 * The graph explorer's labels in the language picked in the menu (#782,
 * ADR-070). The labels live in English in lib/graph-constants.ts, which the
 * graph API reads too, so they are translated where they are shown and not
 * where they are defined.
 *
 * Several of them join a name and its explanation with an em dash, which the
 * dictionaries do not hold (house style). The key reads a colon in its place,
 * or a comma where the sentence simply goes on ("..., with their contracts"),
 * and so does the English the page shows.
 */
const EM_DASH = String.fromCharCode(0x2014);
 
/** A label from graph-constants as its dictionary key. */
export function graphKey(text: string): string {
  const [first, ...rest] = text.split(EM_DASH).map((p) => p.trim());
  let out = first;
  for (const next of rest) {
    const goesOn = out.includes(",") || /^(with|and|ready)\b/.test(next);
    out += (goesOn ? ", " : ": ") + next;
  }
  return out;
}