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

Function parseSignificantPrecision

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

Source from the content-addressed store, hash-verified

49const CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/
50
51function parseSignificantPrecision(str: string): ExtendedNumberFormatOptions {
52 const result: ExtendedNumberFormatOptions = {}
53 if (str[str.length - 1] === 'r') {
54 result.roundingPriority = 'morePrecision'
55 } else if (str[str.length - 1] === 's') {
56 result.roundingPriority = 'lessPrecision'
57 }
58 str.replace(
59 SIGNIFICANT_PRECISION_REGEX,
60 function (_: string, g1: string, g2: string | number) {
61 // @@@ case
62 if (typeof g2 !== 'string') {
63 result.minimumSignificantDigits = g1.length
64 result.maximumSignificantDigits = g1.length
65 }
66 // @@@+ case
67 else if (g2 === '+') {
68 result.minimumSignificantDigits = g1.length
69 }
70 // .### case
71 else if (g1[0] === '#') {
72 result.maximumSignificantDigits = g1.length
73 }
74 // .@@## or .@@@ case
75 else {
76 result.minimumSignificantDigits = g1.length
77 result.maximumSignificantDigits =
78 g1.length + (typeof g2 === 'string' ? g2.length : 0)
79 }
80 return ''
81 }
82 )
83 return result
84}
85
86function parseSign(str: string): ExtendedNumberFormatOptions | undefined {
87 switch (str) {

Callers 1

parseNumberSkeletonFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected