Collator Sensitivity Levels
You'll learn how to control the strictness of string comparisons by choosing the right sensitivity level in Intl.Collator.
What Are Sensitivity Levels?
When comparing strings across languages, you often need to decide what differences matter. Should "café" and "cafe" be considered equal? What about "Café" and "café"? Sensitivity levels let you specify exactly which character differences to ignore or respect during comparison.
The sensitivity option in Intl.Collator accepts four values:
base — Ignores Almost Everything
Only base characters matter. Accents, case, and variants are all ignored.
const collator = new Intl.Collator('en', { sensitivity: 'base' });
collator.compare('café', 'cafe'); // 0 (equal)
collator.compare('Café', 'cafe'); // 0 (equal)
collator.compare('a', 'b'); // negative (different base)
accent — Respects Accents, Ignores Case
Base characters and accents must match, but case doesn't matter.
const collator = new Intl.Collator('en', { sensitivity: 'accent' });
collator.compare('café', 'cafe'); // positive (different accents)
collator.compare('Café', 'café'); // 0 (same accents, case ignored)
case — Respects Case, Ignores Accents
Base characters and case must match, but accents are ignored.
const collator = new Intl.Collator('en', { sensitivity: 'case' });
collator.compare('café', 'cafe'); // 0 (accents ignored)
collator.compare('Café', 'café'); // negative (different case)
variant — Strictest Comparison
Everything must match: base, accents, case, and other variants.
const collator = new Intl.Collator('en', { sensitivity: 'variant' });
collator.compare('café', 'cafe'); // positive (different)
collator.compare('Café', 'café'); // negative (different)
Key Takeaway: Sensitivity levels (base, accent, case, variant) give you fine-grained control over which character differences matter during locale-aware string comparisons.