refactor: format
TS Lint / ESLint (push) Has been cancelled
TS Lint / Oxlint (push) Has been cancelled
TS Lint / TypeScript (push) Has been cancelled

This commit is contained in:
2026-07-14 11:47:05 +02:00
parent 566f8403ef
commit a9b2e31d81
17 changed files with 432 additions and 183 deletions
+24 -18
View File
@@ -1,48 +1,54 @@
import { CronType } from "@/enums";
import {CronExpressionParser} from "cron-parser";
import { CronExpressionParser } from "cron-parser";
export function parseCron(cron: string | null): { type: CronType, value: number } {
export function parseCron(cron: string | null): {
type: CronType;
value: number;
} {
let value: RegExpMatchArray | null;
if (cron === null) {
return {
type: CronType.ONE_TIME,
value: 0
}
value: 0,
};
} else if ((value = /^0 (\d+) \* \* \*$/i.exec(cron)) !== null) {
return {
type: CronType.EVERY_DAY,
value: parseInt(value[1] ?? '')
}
value: parseInt(value[1] ?? ""),
};
} else if ((value = /^0 0 \* \* (\d+)$/i.exec(cron)) !== null) {
return {
type: CronType.EVERY_WEEK,
value: parseInt(value[1] ?? '')
}
value: parseInt(value[1] ?? ""),
};
} else if ((value = /^0 0 (\d+) \* \*$/i.exec(cron)) !== null) {
return {
type: CronType.EVERY_MONTH,
value: parseInt(value[1] ?? '')
}
value: parseInt(value[1] ?? ""),
};
} else if ((value = /^0 0 1 (\d+) \*$/i.exec(cron)) !== null) {
return {
type: CronType.EVERY_YEAR,
value: parseInt(value[1] ?? '')
}
value: parseInt(value[1] ?? ""),
};
} else {
return {
type: CronType.SPECIFIC,
value: 0
}
value: 0,
};
}
}
export function getCron(type: CronType, value: number, fallback: string): string | null {
switch(type) {
export function getCron(
type: CronType,
value: number,
fallback: string,
): string | null {
switch (type) {
case CronType.EVERY_DAY:
return `0 ${value.toFixed(0)} * * *`;
case CronType.EVERY_WEEK:
return `0 0 * * ${value.toFixed(0)}`
return `0 0 * * ${value.toFixed(0)}`;
case CronType.EVERY_MONTH:
return `0 0 ${value.toFixed(0)} * *`;
case CronType.EVERY_YEAR: