Skip to main content

Locale-aware string comparisons

Compare case, accents and Unicode text with actual search collation data

collator produces an internal typed value for the third argument of ==, !=, <, <=, > and >=. commonCollatorSearch reports the five-locale search subset documented here. The options are case-sensitive, diacritic-sensitive and locale, each accepting expressions. Both sensitivity options default to false; omitted locale consistently selects en-US.

import { map } from 'sqsmap';
map.addSource('names', { type: 'geojson', data: {
  type: 'Feature', id: 7, properties: { name: 'Café' },
  geometry: { type: 'Point', coordinates: [0, 0] }
} });
map.addLayer({ id: 'matching', type: 'circle', source: 'names',
  filter: ['==', ['get', 'name'], 'CAFE', ['collator', {
    locale: 'fr-FR', 'case-sensitive': false, 'diacritic-sensitive': false
  }]],
  paint: { 'circle-color': '#00ff00', 'circle-radius': 8 }
});
map.jumpTo({ center: [0, 0], zoom: 2 });
await map.sqs.flush();

The common implementation uses real Unicode search collation data, matching the reference's usage: search. Four sensitivity combinations, composed/decomposed characters, German characters and Chinese/Japanese text follow that data. This is not a promise of ordinary dictionary sorting. Unprovided options such as numeric are rejected. Existing two-argument comparisons remain unchanged. Three-argument equality/inequality use ordinary comparison when dynamic inputs are not both strings; ordered three-argument comparisons require strings.

Supported locales are en-US, zh-CN, de-DE, fr-FR and ja-JP. Other locales and Unicode extensions fail with capability unavailable, without consulting browser or OS defaults. resolved-locale separately resolves the public locale under ordinary-sort language rules. The five results are en-US, zh-CN, de, fr and ja; de-DE is not simply echoed, and internal search configuration is not exposed.

The collator remains an internal type: typeof returns collator, lexical variables and branches retain identity, and JSON objects cannot impersonate it. It cannot be converted to ordinary strings, numbers or serialized data. Dynamic option dependencies, lazy bindings and existing expression budgets apply. Failed layer/source/output candidates preserve rendering and identity.

Runtime comparison uses pure Rust ICU4X and fixed official ICU export data, offline. Generation tooling and downloads are excluded from the map runtime. The complete Unicode license and source SHA records ship with the SDK. Syntax and search/locale resolution follow the frozen MapLibre type, independently integrated into this project's common core.

Copy portable-collator.js, or run the complete browser page. The same script checks four sensitivities, six comparisons, type/locale resolution, dynamic options, atomic failures and an actual green point. Other locales, complete style domains, devices and formal release remain pending.

Filters containing collator, resolved-locale or number-format perform actual lazy evaluation before candidate commit. Invalid dynamic locale or precision returns a filter error and preserves the source/layer. Existing error fallback is retained for filters without these new operators.