@@ -14,8 +14,9 @@ function formatValue<Shape, Key extends keyof Shape>(
14
14
label : Key ,
15
15
value : Shape [ Key ] ,
16
16
formatters : ValueFormatters < Shape > ,
17
+ defaultFormatter ?: ( value : Shape [ Key ] ) => string | undefined ,
17
18
) {
18
- const formatter = formatters [ label ] ;
19
+ const formatter = formatters [ label ] || defaultFormatter ;
19
20
const formattedValue = formatter ? formatter ( value ) : value ;
20
21
21
22
return String ( formattedValue ?? '' ) ;
@@ -24,14 +25,16 @@ function formatValue<Shape, Key extends keyof Shape>(
24
25
interface CreateInfoFormatterOptions < Shape > {
25
26
values ?: ValueFormatters < Shape > ,
26
27
labels ?: LabelMap < Shape > ,
28
+ defaultValueFormatter ?: ( value : Shape [ keyof Shape ] ) => string | undefined ,
27
29
}
28
30
29
31
export function createInfoFormatter < Shape extends Record < string , any > > ( {
30
32
values : valueFormatters ,
31
33
labels : labelMap ,
34
+ defaultValueFormatter,
32
35
} : CreateInfoFormatterOptions < Shape > ) {
33
36
return < Key extends keyof Shape > ( label : Key , value : Shape [ Key ] ) => ( {
34
37
label : formatLabel ( label , labelMap || { } ) ,
35
- value : formatValue ( label , value , valueFormatters || { } ) ,
38
+ value : formatValue ( label , value , valueFormatters || { } , defaultValueFormatter ) ,
36
39
} ) ;
37
40
}
0 commit comments