(
value: any,
// For high performance, do not omit the second param.
opt: {
// Default type: 'number'. There is no 'unknown' type. That is, a string
// will be parsed to NaN if do not set `type` as 'ordinal'. It has been
// the logic in `List.ts` for long time. Follow the same way if you need
// to get same result as List did from a raw value.
type?: DimensionType
}
)
| 34 | * For backward compatibility, do not modify it until you have to! |
| 35 | */ |
| 36 | export function parseDataValue( |
| 37 | value: any, |
| 38 | // For high performance, do not omit the second param. |
| 39 | opt: { |
| 40 | // Default type: 'number'. There is no 'unknown' type. That is, a string |
| 41 | // will be parsed to NaN if do not set `type` as 'ordinal'. It has been |
| 42 | // the logic in `List.ts` for long time. Follow the same way if you need |
| 43 | // to get same result as List did from a raw value. |
| 44 | type?: DimensionType |
| 45 | } |
| 46 | ): ParsedValue { |
| 47 | // Performance sensitive. |
| 48 | const dimType = opt && opt.type; |
| 49 | if (dimType === 'ordinal') { |
| 50 | // If given value is a category string |
| 51 | return value; |
| 52 | } |
| 53 | |
| 54 | if (dimType === 'time' |
| 55 | // spead up when using timestamp |
| 56 | && !isNumber(value) |
| 57 | && value != null |
| 58 | && value !== '-' |
| 59 | ) { |
| 60 | value = +parseDate(value); |
| 61 | } |
| 62 | |
| 63 | // dimType defaults 'number'. |
| 64 | // If dimType is not ordinal and value is null or undefined or NaN or '-', |
| 65 | // parse to NaN. |
| 66 | // number-like string (like ' 123 ') can be converted to a number. |
| 67 | // where null/undefined or other string will be converted to NaN. |
| 68 | return (value == null || value === '') |
| 69 | ? NaN |
| 70 | // If string (like '-'), using '+' parse to NaN |
| 71 | // If object, also parse to NaN |
| 72 | : Number(value); |
| 73 | }; |
| 74 | |
| 75 | |
| 76 |
no test coverage detected
searching dependent graphs…