MCPcopy
hub / github.com/formatjs/formatjs / tailoringEntries

Function tailoringEntries

packages/intl-collator/compare.ts:324–370  ·  view source on GitHub ↗
(
  locale: string,
  collation: string,
  visited = new Set<string>()
)

Source from the content-addressed store, hash-verified

322}
323
324function tailoringEntries(
325 locale: string,
326 collation: string,
327 visited = new Set<string>()
328): readonly TailoringEntry[] {
329 const key = `${locale}|${collation}`
330 if (tailoringCache.has(key)) {
331 return tailoringCache.get(key)!
332 }
333 if (visited.has(key)) {
334 return []
335 }
336 visited.add(key)
337
338 const collationData = packedCollation(locale, collation)
339 const entries: TailoringEntry[] = []
340 const rules = collationData?.rules || []
341 let reset: PackedLDMLReset | undefined
342 let relations: PackedLDMLRelation[] = []
343
344 function flushRelations() {
345 if (reset && relations.length > 0) {
346 addTailoredRelationGroup(entries, reset[1], reset[2], relations)
347 }
348 relations = []
349 }
350
351 for (const rule of rules) {
352 if (rule[0] === 'setting') {
353 // Settings break the current LDML rule chain. Imports contribute their
354 // compiled tailoring entries at this point in rule order.
355 // https://www.unicode.org/reports/tr35/tr35-collation.html#Collation_Settings
356 flushRelations()
357 entries.push(...importedTailorings(rule, visited))
358 } else if (rule[0] === 'reset') {
359 flushRelations()
360 reset = rule
361 } else if (rule[0] === 'relation') {
362 relations.push(rule)
363 }
364 }
365 flushRelations()
366
367 entries.sort((left, right) => right.codePoints.length - left.codePoints.length)
368 tailoringCache.set(key, entries)
369 return entries
370}
371
372function lookupTailoredElements(
373 entries: readonly TailoringEntry[],

Callers 2

importedTailoringsFunction · 0.85
comparePreparedStringsFunction · 0.85

Calls 5

packedCollationFunction · 0.85
flushRelationsFunction · 0.85
importedTailoringsFunction · 0.85
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected