UNPKG

cronz-scheduler

Version:

A lightweight cron and interval scheduler for Node.js written in TypeScript.

30 lines (29 loc) 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateCron = validateCron; exports.matchTime = matchTime; function validateCron(expr) { const parts = expr.trim().split(" "); return parts.length === 5; } function matchTime(field, value) { if (field === "*") return true; const parts = field.split(","); return parts.some((part) => { if (part.includes("/")) { const [base, step] = part.split("/"); const baseRange = base === "*" ? [0, 59] : base.split("-").map(Number); const stepNum = parseInt(step); const [start, end] = baseRange.length === 2 ? baseRange : [0, 59]; return value >= start && value <= end && (value - start) % stepNum === 0; } else if (part.includes("-")) { const [start, end] = part.split("-").map(Number); return value >= start && value <= end; } else { return parseInt(part) === value; } }); }