JavaScript

Normalize Unicode text before comparison

Normalize strings to a chosen Unicode normalization form before comparing visually equivalent text. NFC combines supported character sequences into their canonical composed form.

Worked example

Node.js example · save as example.mjs and run node example.mjs

const composed = "\u00e9";
const decomposed = "e\u0301";
console.log(composed === decomposed);
console.log(composed.normalize("NFC") === decomposed.normalize("NFC"));

How it works

The strings render similarly but contain different code-point sequences. NFC makes canonically equivalent sequences comparable under ordinary string equality. This can help deduplicate names imported from systems that use different Unicode representations.

Limits and mistakes

Normalization does not remove accents, change letter case, or identify all visually confusable characters. Compatibility forms such as NFKC can change distinctions that matter. Choose the normalization policy for the domain rather than applying it indiscriminately.

Check the result

Expect false and then true. Test scripts and symbols relevant to your input. Keep the original display text when normalization is only needed for a comparison key.

Sources

Reference documentation for the behavior used in this guide: