( skeleton: string )
| 10 | } |
| 11 | |
| 12 | export function parseNumberSkeletonFromString( |
| 13 | skeleton: string |
| 14 | ): NumberSkeletonToken[] { |
| 15 | if (skeleton.length === 0) { |
| 16 | throw new Error('Number skeleton cannot be empty') |
| 17 | } |
| 18 | // Parse the skeleton |
| 19 | const stringTokens = skeleton |
| 20 | .split(WHITE_SPACE_REGEX) |
| 21 | .filter(x => x.length > 0) |
| 22 | |
| 23 | const tokens: NumberSkeletonToken[] = [] |
| 24 | for (const stringToken of stringTokens) { |
| 25 | let stemAndOptions = stringToken.split('/') |
| 26 | if (stemAndOptions.length === 0) { |
| 27 | throw new Error('Invalid number skeleton') |
| 28 | } |
| 29 | |
| 30 | const [stem, ...options] = stemAndOptions |
| 31 | for (const option of options) { |
| 32 | if (option.length === 0) { |
| 33 | throw new Error('Invalid number skeleton') |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | tokens.push({stem, options}) |
| 38 | } |
| 39 | return tokens |
| 40 | } |
| 41 | |
| 42 | function icuUnitToEcma(unit: string): ExtendedNumberFormatOptions['unit'] { |
| 43 | return unit.replace(/^(.*?)-/, '') as ExtendedNumberFormatOptions['unit'] |
no outgoing calls
no test coverage detected