(str: string | number, throwOnError = true)
| 152 | const MEMORY_UNITS = { k: 1 / 1024, m: 1, g: 1024 } as Record<string, number>; |
| 153 | |
| 154 | export function parseTimeMS(str: string | number, throwOnError = true) { |
| 155 | if (typeof str === 'number' || Number.isSafeInteger(+str)) return +str; |
| 156 | const match = TIME_RE.exec(str); |
| 157 | if (!match && throwOnError) throw new Error(`${str} error parsing time`); |
| 158 | if (!match) return 1000; |
| 159 | return Math.floor(Number.parseFloat(match[1]) * TIME_UNITS[match[2].toLowerCase()]); |
| 160 | } |
| 161 | |
| 162 | export function parseMemoryMB(str: string | number, throwOnError = true) { |
| 163 | if (typeof str === 'number' || Number.isSafeInteger(+str)) return +str; |
no outgoing calls
no test coverage detected