Files
calendar/packages/lib/intervalLimits/intervalLimit.ts
T
Alex van AndelandGitHub 0565e23818 refactor: Remove intervalLimits from @calcom/lib and export directly (#19710)
* refactor: Remove intervalLimits from @calcom/lib and export directly

* Tackle other places that use parseBookingLimit/parseDurationLimit

* More type fixups that were hidden by previous fails

* Fixed up booking-limits file

* Remove server-only
2025-03-05 19:32:53 +00:00

18 lines
742 B
TypeScript

import type { IntervalLimitUnit, IntervalLimitKey } from "./intervalLimitSchema";
export const ascendingLimitKeys: IntervalLimitKey[] = ["PER_DAY", "PER_WEEK", "PER_MONTH", "PER_YEAR"];
export const descendingLimitKeys = [...ascendingLimitKeys].reverse();
function isIntervalLimitUnit(value: string): value is IntervalLimitUnit {
return ["day", "week", "month", "year"].includes(value); // Replace with actual values
}
/**
* Turns `PER_DAY` into `day`, `PER_WEEK` into `week` etc.
*/
export function intervalLimitKeyToUnit(key: IntervalLimitKey): IntervalLimitUnit {
const extracted = key.split("_")[1].toLowerCase();
if (isIntervalLimitUnit(extracted)) return extracted;
throw new Error(`Invalid interval limit key: ${key}`);
}