refactor: dedupe trim reader aliases

This commit is contained in:
Peter Steinberger
2026-04-07 08:56:52 +01:00
parent 9c9b0effda
commit 7087845f58
8 changed files with 98 additions and 137 deletions

View File

@@ -75,16 +75,16 @@ export function applyExistingCronSchedulePatch(
}
function normalizeScheduleOptions(options: ScheduleOptionInput): NormalizedScheduleOptions {
const staggerRaw = readTrimmedString(options.stagger);
const staggerRaw = normalizeOptionalString(options.stagger) ?? "";
const useExact = Boolean(options.exact);
if (staggerRaw && useExact) {
throw new Error("Choose either --stagger or --exact, not both");
}
return {
at: readTrimmedString(options.at),
every: readTrimmedString(options.every),
cronExpr: readTrimmedString(options.cron),
tz: readOptionalString(options.tz),
at: normalizeOptionalString(options.at) ?? "",
every: normalizeOptionalString(options.every) ?? "",
cronExpr: normalizeOptionalString(options.cron) ?? "",
tz: normalizeOptionalString(options.tz),
requestedStaggerMs: parseCronStaggerMs({ staggerRaw, useExact }),
};
}
@@ -125,11 +125,3 @@ function resolveDirectSchedule(options: NormalizedScheduleOptions): CronSchedule
}
return undefined;
}
function readOptionalString(value: unknown): string | undefined {
return normalizeOptionalString(value);
}
function readTrimmedString(value: unknown): string {
return typeof value === "string" ? value.trim() : "";
}