@dudousxd/nestjs-telescope
Version:
Laravel Telescope-style observability console for NestJS — core: watchers, recorder, correlation, SQLite store, headless API.
22 lines • 648 B
JavaScript
// packages/core/src/config/parse-duration.ts
const DURATION_UNITS = {
ms: 1,
s: 1_000,
m: 60_000,
h: 3_600_000,
d: 86_400_000,
};
/** Convert a duration (raw ms number, or `<int><ms|s|m|h|d>` string) to ms.
* Throws on an unparseable string. */
export function durationToMs(duration) {
if (typeof duration === 'number') {
return duration;
}
const match = /^(\d+)(ms|s|m|h|d)$/.exec(duration.trim());
if (!match) {
throw new Error(`Invalid duration: ${duration}`);
}
const unit = match[2];
return Number(match[1]) * DURATION_UNITS[unit];
}
//# sourceMappingURL=parse-duration.js.map