mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-20 00:37:35 +00:00
24 lines
617 B
TypeScript
24 lines
617 B
TypeScript
import ms, { StringValue } from "ms";
|
|
|
|
const convertToMilliseconds = (exp: string | number): number => {
|
|
if (typeof exp === "number") {
|
|
return exp * 1000;
|
|
}
|
|
|
|
const result = ms(exp as StringValue);
|
|
if (typeof result !== "number") {
|
|
throw new Error(`Invalid expiration format: ${exp}`);
|
|
}
|
|
|
|
return result;
|
|
};
|
|
|
|
export const getMinExpiresIn = (exp1: string | number, exp2: string | number): string | number => {
|
|
const ms1 = convertToMilliseconds(exp1);
|
|
const ms2 = convertToMilliseconds(exp2);
|
|
|
|
return ms1 <= ms2 ? exp1 : exp2;
|
|
};
|
|
|
|
export const convertMsToSecond = (time: number) => time / 1000;
|