( pattern: string, placeables: Record<string, Placeable | Placeable[]> )
| 162 | } |
| 163 | |
| 164 | function 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 | |
| 190 | export default class ListFormat { |
| 191 | constructor(locales?: string | string[], options?: IntlListFormatOptions) { |
no test coverage detected