@@ -14,8 +14,9 @@ function formatValue<Shape, Key extends keyof Shape>(
1414 label : Key ,
1515 value : Shape [ Key ] ,
1616 formatters : ValueFormatters < Shape > ,
17+ defaultFormatter ?: ( value : Shape [ Key ] ) => string | undefined ,
1718) {
18- const formatter = formatters [ label ] ;
19+ const formatter = formatters [ label ] || defaultFormatter ;
1920 const formattedValue = formatter ? formatter ( value ) : value ;
2021
2122 return String ( formattedValue ?? '' ) ;
@@ -24,14 +25,16 @@ function formatValue<Shape, Key extends keyof Shape>(
2425interface CreateInfoFormatterOptions < Shape > {
2526 values ?: ValueFormatters < Shape > ,
2627 labels ?: LabelMap < Shape > ,
28+ defaultValueFormatter ?: ( value : Shape [ keyof Shape ] ) => string | undefined ,
2729}
2830
2931export function createInfoFormatter < Shape extends Record < string , any > > ( {
3032 values : valueFormatters ,
3133 labels : labelMap ,
34+ defaultValueFormatter,
3235} : CreateInfoFormatterOptions < Shape > ) {
3336 return < Key extends keyof Shape > ( label : Key , value : Shape [ Key ] ) => ( {
3437 label : formatLabel ( label , labelMap || { } ) ,
35- value : formatValue ( label , value , valueFormatters || { } ) ,
38+ value : formatValue ( label , value , valueFormatters || { } , defaultValueFormatter ) ,
3639 } ) ;
3740}
0 commit comments