14 lines
439 B
TypeScript
14 lines
439 B
TypeScript
export const parseTimeoutToMs = (timeout: string) => {
|
|
const match = timeout.match(/(?<number>\d+)(?<unit>d|h|m)/gi)?.groups || {};
|
|
const { number, unit } = match;
|
|
switch (unit) {
|
|
case 'd':
|
|
return 1000 * 60 * 60 * 24 * parseInt(number);
|
|
case 'h':
|
|
return 1000 * 60 * 60 * parseInt(number);
|
|
case 'm':
|
|
default:
|
|
return 1000 * 60 * parseInt(number) || 1;
|
|
}
|
|
};
|