MCPcopy Index your code
hub / github.com/formatjs/formatjs / parseNumberSkeletonFromString

Function parseNumberSkeletonFromString

packages/icu-skeleton-parser/number.ts:12–40  ·  view source on GitHub ↗
(
  skeleton: string
)

Source from the content-addressed store, hash-verified

10}
11
12export 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
42function icuUnitToEcma(unit: string): ExtendedNumberFormatOptions['unit'] {
43 return unit.replace(/^(.*?)-/, '') as ExtendedNumberFormatOptions['unit']

Callers 2

index.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected