(input: Input)
| 240 | * @since 4.0.0 |
| 241 | */ |
| 242 | export const fromInputUnsafe = (input: Input): Duration => { |
| 243 | switch (typeof input) { |
| 244 | case "number": |
| 245 | return millis(input) |
| 246 | case "bigint": |
| 247 | return nanos(input) |
| 248 | case "string": { |
| 249 | if (input === "Infinity") { |
| 250 | return infinity |
| 251 | } |
| 252 | if (input === "-Infinity") { |
| 253 | return negativeInfinity |
| 254 | } |
| 255 | const match = DURATION_REGEXP.exec(input) |
| 256 | if (!match) break |
| 257 | const [_, valueStr, unit] = match |
| 258 | if (unit === "nano" || unit === "nanos") { |
| 259 | return nanos(parseNanos(valueStr, bigint1)) |
| 260 | } |
| 261 | if (unit === "micro" || unit === "micros") { |
| 262 | return nanos(parseNanos(valueStr, bigint1e3)) |
| 263 | } |
| 264 | const value = Number(valueStr) |
| 265 | switch (unit) { |
| 266 | case "milli": |
| 267 | case "millis": |
| 268 | return millis(value) |
| 269 | case "second": |
| 270 | case "seconds": |
| 271 | return seconds(value) |
| 272 | case "minute": |
| 273 | case "minutes": |
| 274 | return minutes(value) |
| 275 | case "hour": |
| 276 | case "hours": |
| 277 | return hours(value) |
| 278 | case "day": |
| 279 | case "days": |
| 280 | return days(value) |
| 281 | case "week": |
| 282 | case "weeks": |
| 283 | return weeks(value) |
| 284 | } |
| 285 | break |
| 286 | } |
| 287 | case "object": { |
| 288 | if (input === null) break |
| 289 | if (TypeId in input) return input as Duration |
| 290 | if (Array.isArray(input)) { |
| 291 | if (input.length !== 2 || !input.every(isNumber)) { |
| 292 | return invalid(input) |
| 293 | } |
| 294 | if (Number.isNaN(input[0]) || Number.isNaN(input[1])) { |
| 295 | return zero |
| 296 | } |
| 297 | if (input[0] === -Infinity || input[1] === -Infinity) { |
| 298 | return negativeInfinity |
| 299 | } |
no test coverage detected