(value)
| 15 | |
| 16 | function arg(name, fallback = null) { |
| 17 | const i = args.indexOf(name) |
| 18 | if (i < 0) return fallback |
| 19 | if (i + 1 >= args.length) throw new Error(`Missing value for ${name}`) |
| 20 | return args[i + 1] |
| 21 | } |
| 22 | |
| 23 | function has(name) { |
| 24 | return args.includes(name) |
| 25 | } |
| 26 | |
| 27 | function parseMs(value) { |
| 28 | const v = String(value ?? "0s").trim().toLowerCase() |
| 29 | if (v === "0" || v === "0s" || v === "now") return 0 |
| 30 | |
| 31 | const m = v.match(/^(\d+(?:\.\d+)?)\s*(ms|s|sec|secs|m|min|mins|h|hr|hrs|d|day|days)$/) |
| 32 | if (!m) throw new Error(`Invalid duration: ${value}`) |
| 33 | |
| 34 | const n = Number(m[1]) |
| 35 | const unit = m[2] |
| 36 | |
| 37 | if (unit === "ms") return n |
no outgoing calls
no test coverage detected