(
value: unknown,
valueType: DimensionType,
useUTC: boolean
)
| 62 | * a value and it might look like a bug. |
| 63 | */ |
| 64 | export function makeValueReadable( |
| 65 | value: unknown, |
| 66 | valueType: DimensionType, |
| 67 | useUTC: boolean |
| 68 | ): string { |
| 69 | const USER_READABLE_DEFUALT_TIME_PATTERN = '{yyyy}-{MM}-{dd} {HH}:{mm}:{ss}'; |
| 70 | |
| 71 | function stringToUserReadable(str: string): string { |
| 72 | return (str && zrUtil.trim(str)) ? str : '-'; |
| 73 | } |
| 74 | function isNumberUserReadable(num: number): boolean { |
| 75 | return isNullableNumberFinite(num); |
| 76 | } |
| 77 | |
| 78 | const isTypeTime = valueType === 'time'; |
| 79 | const isValueDate = value instanceof Date; |
| 80 | if (isTypeTime || isValueDate) { |
| 81 | const date = isTypeTime ? parseDate(value) : value; |
| 82 | if (!isNaN(+date)) { |
| 83 | return timeFormat(date, USER_READABLE_DEFUALT_TIME_PATTERN, useUTC); |
| 84 | } |
| 85 | else if (isValueDate) { |
| 86 | return '-'; |
| 87 | } |
| 88 | // In other cases, continue to try to display the value in the following code. |
| 89 | } |
| 90 | |
| 91 | if (valueType === 'ordinal') { |
| 92 | return zrUtil.isStringSafe(value) |
| 93 | ? stringToUserReadable(value) |
| 94 | : zrUtil.isNumber(value) |
| 95 | ? (isNumberUserReadable(value) ? value + '' : '-') |
| 96 | : '-'; |
| 97 | } |
| 98 | // By default. |
| 99 | const numericResult = numericToNumber(value); |
| 100 | return isNumberUserReadable(numericResult) |
| 101 | ? addCommas(numericResult) |
| 102 | : zrUtil.isStringSafe(value) |
| 103 | ? stringToUserReadable(value) |
| 104 | : typeof value === 'boolean' |
| 105 | ? value + '' |
| 106 | : '-'; |
| 107 | } |
| 108 | |
| 109 | |
| 110 | const TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g']; |
no test coverage detected