Expand description
Unicode normalization: the four forms String.prototype.normalize offers.
§22.1.3.13 defines the method only by pointing at Unicode Standard Annex #15, so this is that annex’s algorithm and nothing else. It is the same computation four times with two switches — whether compatibility mappings apply, and whether the result is recomposed:
| form | compatibility mappings | recomposes |
|---|---|---|
| NFD | no | no |
| NFC | no | yes |
| NFKD | yes | no |
| NFKC | yes | yes |
§Why the tables are separate from this
[crate::normalize_tables] is generated from the Unicode Character Database, and it
stores the single-step mappings UnicodeData.txt spells — U+1E0B maps to
U+0064 U+0307, not to the fully expanded sequence. Expanding a chain is [expand]’s
job. A precomputed closure in the table would be a derived artifact: it would agree with
the UCD only as long as the generator’s closure rule did, and a bug there would be
invisible in the table.
§Hangul is arithmetic
The 11172 Hangul syllables decompose to jamo and recompose from them by formula, so they
have no entries anywhere in the tables — UnicodeData.txt does not list them either.
Both directions are handled before any table is consulted.
§What is deliberately absent: the quick-check tables
UAX #15 publishes NFC_Quick_Check and friends so an implementation can answer “is this
already normalized?” without doing the work, and real engines ship them. They are a pure
optimisation: skipping them changes no result. The other half of that fast path costs
nothing to keep — ASCII is in all four normal forms — and it covers the case that
shows up in real code. Carrying ~1400 more ranges for the rest would add a second
mechanism whose only failure mode is being slow, when calling it “slow” means a few
allocations on a string that is not ASCII. The generator asserts the ASCII property
instead of this module assuming it.
Enums§
- Form
- One of the four Unicode Normalization Forms.
Functions§
- normalize
- Normalize
textintoform.