@mann-conomy/job-scheduler
Version:
A simple background job scheduler for the Mann-Conomy project.
40 lines • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateCronTime = validateCronTime;
exports.validateTimeZone = validateTimeZone;
exports.validateCronOptions = validateCronOptions;
const cron_1 = require("cron");
function validateCronTime(expression) {
const result = (0, cron_1.validateCronExpression)(expression.toString());
if (!result.valid && result.error) {
throw new TypeError(result.error.message, {
cause: result.error.cause
});
}
return expression;
}
function validateTimeZone(timeZone) {
try {
Intl.DateTimeFormat(undefined, { timeZone });
return {
valid: true,
error: null,
};
}
catch (error) {
return {
error,
valid: false,
};
}
}
function validateCronOptions(timeZone, options) {
if (options.timeZone) {
const result = validateTimeZone(options.timeZone);
if (!result.valid && result.error) {
throw new TypeError("Invalid format or value for the specified time zone.");
}
}
return Object.assign({ timeZone }, options);
}
//# sourceMappingURL=utils.js.map