natural-cron
Version:
Natural Cron is a easy-to-use Node.js library for creating and validating cron expressions with natural, human-readable APIs.
72 lines (71 loc) • 2.87 kB
TypeScript
import { ScheduleUnit } from './interfaces';
/**
* Class to construct a cron expression with a fluent API.
*/
export declare class CronExpressionBuilder {
private readonly schedule;
/**
* Initializes a new instance of the CronExpressionBuilder class.
*/
constructor();
/**
* Ensures that all parts of the cron schedule have default values.
* This method sets defaults for minute, hour, dayOfMonth, month, and dayOfWeek
* if they are not already specified. Defaults to '0' for minute and
* wildcards '*' for other fields to represent "every" value.
*/
private ensureDefaultValues;
/**
* Sets the job to run at specific minutes.
* @param {Array<number>} minutes - Minute(s) at which the job should run.
* @returns {this} The instance of CronExpressionBuilder for chaining.
*/
atMinutes(minutes: Array<number>): this;
/**
* Sets the job to run at a specific hour.
* @param {Array<number>} hours - Hour at which the job should run.
* @returns {this} The instance of CronExpressionBuilder for chaining.
*/
atHours(hours: number[]): this;
/**
* Sets the job to run at a specific time.
* @param {string} time - Time in HH:MM format.
* @returns {this} The instance of CronExpressionBuilder for chaining.
*/
atTime(time: string): this;
/**
* Sets the frequency of the job based on the specified unit.
* @param {string} unit - The time unit (e.g., 'minute', 'hour').
* @returns {this} The instance of CronExpressionBuilder for chaining.
*/
every(unit: string): this;
/**
* Sets the job to run at a specified interval for the given unit.
* @param {ScheduleUnit} unit - The unit of time ('minute', 'hour', 'day', etc.).
* @param {number} interval - The interval at which the job should run.
* @returns {this} The instance of CronExpressionBuilder for chaining.
*/
everyX(interval: number, unit: ScheduleUnit): this;
/**
* Specifies the days of the week when a job should run.
* @param {Array<number>} days - Day(s) of the week.
*/
onWeekDays(days: Array<number>): this;
/**
* Specifies the days of the month when a job should run.
* @param {Array<number>} days - Day(s) of the month.
* @returns {this} The instance of CronExpressionBuilder for chaining.
*/
onDaysOfMonth(days: Array<number>): this;
/**
* Specifies the months when a job should run.
* @param {Array<number>} months - Month(s).
* @returns {this} The instance of CronExpressionBuilder for chaining.
*/
duringMonths(months: Array<number>): this;
/**
* Compiles the individual parts of the schedule into a cron expression.
* @returns {string} The cron expression representing the schedule.
*/
compile(): string;
}