@@ -73,9 +73,17 @@ export function formatPopulation(info: { population?: number }): string {
7373 return info . population . toLocaleString ( ) ;
7474}
7575
76- const f = format ( ',.1f' ) ;
77- const count = format ( '~s' ) ;
78- const basePercentFormatter = format ( '.2%' ) ;
76+ export const formatSpecifiers = {
77+ raw : ',.2f' ,
78+ raw_count : '~s' ,
79+ count : '~s' ,
80+ fraction : ',.2f' ,
81+ percent : '.2f' ,
82+ per100k : ',.1f' ,
83+ } ;
84+
85+ const generic = format ( ',.1f' ) ;
86+ const fractionAsPercentFormatter = format ( '.2%' ) ;
7987const rawFormatter = format ( ',.2f' ) ;
8088
8189function sign (
@@ -98,34 +106,30 @@ function sign(
98106}
99107
100108export function formatValue ( value ?: number | null , enforceSign = false ) : string {
101- return sign ( value , f , enforceSign ) ;
102- }
103- export function formatCount ( value ?: number | null , enforceSign = false ) : string {
104- return sign ( value , count , enforceSign ) ;
105- }
106- export function formatPercentage ( value ?: number | null , enforceSign = false ) : string {
107- return sign ( value , basePercentFormatter , enforceSign , 1 / 100 ) ;
109+ return sign ( value , generic , enforceSign ) ;
108110}
109111export function formatFraction ( value ?: number | null , enforceSign = false ) : string {
110- return sign ( value , basePercentFormatter , enforceSign ) ;
112+ return sign ( value , fractionAsPercentFormatter , enforceSign ) ;
111113}
112114export function formatRawValue ( value ?: number | null , enforceSign = false ) : string {
113115 return sign ( value , rawFormatter , enforceSign ) ;
114116}
115117
118+ const count = format ( formatSpecifiers . count ) ;
119+ const per100Formatter = format ( formatSpecifiers . percent ) ;
120+
121+ function formatCount ( value ?: number | null , enforceSign = false ) : string {
122+ return sign ( value , count , enforceSign ) ;
123+ }
124+ function formatPer100 ( value ?: number | null , enforceSign = false ) : string {
125+ return sign ( value , per100Formatter , enforceSign ) ;
126+ }
127+
116128export const formatter = {
117129 raw : formatRawValue ,
118130 raw_count : formatCount ,
119131 count : formatCount ,
120132 fraction : formatRawValue ,
121- percent : formatPercentage ,
133+ percent : formatPer100 ,
122134 per100k : formatValue ,
123135} ;
124- export const formatSpecifiers = {
125- raw : ',.2f' ,
126- raw_count : '~s' ,
127- count : '~s' ,
128- fraction : ',.2f' ,
129- percent : '.2f' ,
130- per100k : ',.1f' ,
131- } ;
0 commit comments