MCPcopy
hub / github.com/formatjs/formatjs / printPluralElement

Function printPluralElement

packages/icu-messageformat-parser/printer.ts:233–251  ·  view source on GitHub ↗
(el: PluralElement)

Source from the content-addressed store, hash-verified

231}
232
233function printPluralElement(el: PluralElement) {
234 const type = el.pluralType === 'cardinal' ? 'plural' : 'selectordinal'
235 const keys = Object.keys(el.options).sort((a, b) => {
236 const [pa, sa] = getPluralRuleSortOrder(a)
237 const [pb, sb] = getPluralRuleSortOrder(b)
238 return pa - pb || sa - sb
239 })
240 const msg = [
241 el.value,
242 type,
243 [
244 el.offset ? `offset:${el.offset}` : '',
245 ...keys.map(id => `${id}{${doPrintAST(el.options[id].value, true)}}`),
246 ]
247 .filter(Boolean)
248 .join(' '),
249 ].join(',')
250 return `{${msg}}`
251}

Callers 1

doPrintASTFunction · 0.85

Calls 2

getPluralRuleSortOrderFunction · 0.85
doPrintASTFunction · 0.85

Tested by

no test coverage detected