I have a value that may be a stringified date, or number. I'd like to handle each case differently.
Date values can be any valid date string that can be parsed by a date library, like dayjs. For example: "10/10/2020"
, "10-20-2020"
...
Number values can be actual numbers, or numbers in the form of a string, so values like 5
, "5.3"
, "10"
...
For example ->
const number = parseFloat(value);
if (!isNaN(number)) {
return NumberValueConverter.prototype.toView(number);
}
const date = dayjs(value);
if (date.isValid()) {
return DateValueConverter.prototype.toView(value);
}
This code isn't working though - since date strings like 10-10-2020, 10-10-2020 end up getting parsed to 10
If I do it in reverse, dayjs converts numbers like 10 to a valid date.