MCPcopy
hub / github.com/formatjs/formatjs / deconstructPattern

Function deconstructPattern

packages/intl-listformat/index.ts:164–188  ·  view source on GitHub ↗
(
  pattern: string,
  placeables: Record<string, Placeable | Placeable[]>
)

Source from the content-addressed store, hash-verified

162}
163
164function deconstructPattern(
165 pattern: string,
166 placeables: Record<string, Placeable | Placeable[]>
167) {
168 const patternParts = PartitionPattern(pattern)
169 const result: Placeable[] = []
170 for (const patternPart of patternParts) {
171 const {type: part} = patternPart
172 if (isLiteralPart(patternPart)) {
173 result.push({
174 type: 'literal',
175 value: patternPart.value,
176 })
177 } else {
178 invariant(part in placeables, `${part} is missing from placables`)
179 const subst = placeables[part]
180 if (Array.isArray(subst)) {
181 result.push(...subst)
182 } else {
183 result.push(subst)
184 }
185 }
186 }
187 return result
188}
189
190export default class ListFormat {
191 constructor(locales?: string | string[], options?: IntlListFormatOptions) {

Callers 1

createPartsFromListFunction · 0.85

Calls 3

PartitionPatternFunction · 0.85
isLiteralPartFunction · 0.85
invariantFunction · 0.50

Tested by

no test coverage detected