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:
- Default-ignorable code points are removed, before and after normalising, since
compatibility normalisation can produce one (a Hangul filler).
Acmewith a zero-width joiner inside isAcme. - NFKC. Full-width letters, ligatures, superscripts and the Arabic presentation forms become the plain letters they stand for.
- Case is folded by upper-casing and then lower-casing, with the locale-independent
toUpperCaseandtoLowerCase(never thetoLocalepair, whose answer would depend on the machine). Lower-casing alone is not a case fold: it leavesßbesidessand a final sigma beside a medial one. The round trip maps both pairs together, and it needs no table. - The four letters
I,i,İandıbecome one. The round trip already takes the Turkish dotlessıtoi, throughI. The dotted capitalİlower-cases toifollowed by a combining dot (U+0307), so aniloses every such dot that follows it directly. That is safe because it removes nothing a reader sees:iis a soft-dotted letter, so a dot above replaces its own dot andiwith one dot above, or with several, is drawn asi. 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. - NFKC again, because case mapping can leave a string that is no longer normalised.
- 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.