11cb0ef41Sopenharmony_ciconst hasIntl = typeof Intl === 'object' && !!Intl
21cb0ef41Sopenharmony_ciconst Collator = hasIntl && Intl.Collator
31cb0ef41Sopenharmony_ciconst cache = new Map()
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst collatorCompare = (locale, opts) => {
61cb0ef41Sopenharmony_ci  const collator = new Collator(locale, opts)
71cb0ef41Sopenharmony_ci  return (a, b) => collator.compare(a, b)
81cb0ef41Sopenharmony_ci}
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst localeCompare = (locale, opts) => (a, b) => a.localeCompare(b, locale, opts)
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst knownOptions = [
131cb0ef41Sopenharmony_ci  'sensitivity',
141cb0ef41Sopenharmony_ci  'numeric',
151cb0ef41Sopenharmony_ci  'ignorePunctuation',
161cb0ef41Sopenharmony_ci  'caseFirst',
171cb0ef41Sopenharmony_ci]
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciconst { hasOwnProperty } = Object.prototype
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cimodule.exports = (locale, options = {}) => {
221cb0ef41Sopenharmony_ci  if (!locale || typeof locale !== 'string')
231cb0ef41Sopenharmony_ci    throw new TypeError('locale required')
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci  const opts = knownOptions.reduce((opts, k) => {
261cb0ef41Sopenharmony_ci    if (hasOwnProperty.call(options, k)) {
271cb0ef41Sopenharmony_ci      opts[k] = options[k]
281cb0ef41Sopenharmony_ci    }
291cb0ef41Sopenharmony_ci    return opts
301cb0ef41Sopenharmony_ci  }, {})
311cb0ef41Sopenharmony_ci  const key = `${locale}\n${JSON.stringify(opts)}`
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  if (cache.has(key))
341cb0ef41Sopenharmony_ci    return cache.get(key)
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  const compare = hasIntl
371cb0ef41Sopenharmony_ci    ? collatorCompare(locale, opts)
381cb0ef41Sopenharmony_ci    : localeCompare(locale, opts)
391cb0ef41Sopenharmony_ci  cache.set(key, compare)
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  return compare
421cb0ef41Sopenharmony_ci}
43