(val: JSONValue)
| 34 | * when fails. |
| 35 | */ |
| 36 | export function valToDate(val: JSONValue): Date { |
| 37 | // If it's a unix epoch timestamp... |
| 38 | if (typeof val == 'number') { |
| 39 | const date = new Date(0); // The 0 there is the key, which sets the date to the epoch |
| 40 | date.setUTCMilliseconds(val); |
| 41 | return date; |
| 42 | } |
| 43 | if (typeof val == 'string') { |
| 44 | return new Date(val.toString()); |
| 45 | } |
| 46 | throw new Error(`Cannot be converted into Date: ${val}, is a ${typeof val}`); |
| 47 | } |
| 48 | |
| 49 | /** Returns a number of the value, or throws an error */ |
| 50 | export function valToNumber(val: JSONValue): number { |
no outgoing calls
no test coverage detected