refactor(openworkflow): hoist parseDuration multipliers to module scope#467
refactor(openworkflow): hoist parseDuration multipliers to module scope#467jamescmartinez merged 2 commits intomainfrom
Conversation
hoists the multipliers table and regex in `parseDuration` out of the function body so they aren't rebuilt on every call. also replaces the inline `60 * 60 * 1000` repetitions with named `MINUTE_MS`/`HOUR_MS`/etc constants.
commit: |
There was a problem hiding this comment.
Pull request overview
Hoists parseDuration’s regex and unit-to-millisecond multipliers to module scope to avoid rebuilding them on every call, and introduces named time constants for clearer multiplier definitions.
Changes:
- Added module-scope
SECOND_MS/MINUTE_MS/HOUR_MS/etc constants. - Moved the duration multipliers map and regex out of
parseDurationinto module-level constants. - Updated
parseDurationto reuse the shared constants.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const DURATION_MULTIPLIERS: Record<string, number> = { | ||
| millisecond: 1, | ||
| milliseconds: 1, | ||
| msec: 1, | ||
| msecs: 1, | ||
| ms: 1, |
There was a problem hiding this comment.
DURATION_MULTIPLIERS is typed as Record<string, number>, which drops compile-time validation of the supported units. Since this module already defines the Unit union, consider typing this as Record<Unit, number> (optionally via as const/satisfies) so unit additions/removals stay type-checked.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
hoists the multipliers table and regex in
parseDurationout of the function body so they aren't rebuilt on every call. also replaces the inline60 * 60 * 1000repetitions with namedMINUTE_MS/HOUR_MS/etc constants.