Skip to main content

Function: foldDisplayName()

foldDisplayName(name): string

Defined in: packages/contracts/src/display-name.ts:99

The form two display names are compared under. Names that fold to the same string are treated as one name; the fold is never stored as a name or shown to anyone.

One pass, in order:

  1. Default-ignorable code points are removed, before and after normalising, since compatibility normalisation can produce one (a Hangul filler). Acme with a zero-width joiner inside is Acme.
  2. NFKC. Full-width letters, ligatures, superscripts and the Arabic presentation forms become the plain letters they stand for.
  3. Case is folded by upper-casing and then lower-casing, with the locale-independent toUpperCase and toLowerCase (never the toLocale pair, whose answer would depend on the machine). Lower-casing alone is not a case fold: it leaves ß beside ss and a final sigma beside a medial one. The round trip maps both pairs together, and it needs no table.
  4. The four letters I, i, İ and ı become one. The round trip already takes the Turkish dotless ı to i, through I. The dotted capital İ lower-cases to i followed by a combining dot (U+0307), so an i loses every such dot that follows it directly. That is safe because it removes nothing a reader sees: i is a soft-dotted letter, so a dot above replaces its own dot and i with one dot above, or with several, is drawn as i. Turkish spells different words with these letters, and this fold deliberately ignores that: it decides whether two names can be mistaken for each other, and to a reader of any other language they can. The cost is that two Turkish organisations whose names differ only in the dot collide and one must choose another name.
  5. NFKC again, because case mapping can leave a string that is no longer normalised.
  6. Runs of white space become one space, and the ends are trimmed.

The pass is repeated until it changes nothing, so the result is a fixed point by construction and fold(fold(x)) === fold(x) for every string, which is what lets a stored digest of a fold be compared with a fold computed later. One pass is not always enough, because the case round trip is not: the capital sharp s ẞ (U+1E9E) has no upper-case mapping, so the first pass only lower-cases it to ß, and it takes the second to reach ss. Looping covers that letter and any other the case tables treat the same way, without naming them.

Parameters​

name​

string

A display name, already valid under DisplayName.

Returns​

string

The folded form. It can be empty only for a name the schema would refuse.