cron-parser
Version:
Node.js library for parsing crontab instructions
90 lines (89 loc) • 2.87 kB
TypeScript
import { CronChars, CronConstraints, CronFieldType, CronMax, CronMin } from './types';
export type SerializedCronField = {
wildcard: boolean;
values: (number | string)[];
};
/**
* Represents a field within a cron expression.
* This is a base class and should not be instantiated directly.
* @class CronField
*/
export declare abstract class CronField {
#private;
/**
* Returns the minimum value allowed for this field.
*/
static get min(): CronMin;
/**
* Returns the maximum value allowed for this field.
*/
static get max(): CronMax;
/**
* Returns the allowed characters for this field.
*/
static get chars(): readonly CronChars[];
/**
* Returns the regular expression used to validate this field.
*/
static get validChars(): RegExp;
/**
* Returns the constraints for this field.
*/
static get constraints(): CronConstraints;
/**
* CronField constructor. Initializes the field with the provided values.
* @param {number[] | string[]} values - Values for this field
* @param {boolean} [wildcard=false] - Whether this field is a wildcard
* @throws {TypeError} if the constructor is called directly
* @throws {Error} if validation fails
*/
protected constructor(values: (number | string)[], wildcard?: boolean);
/**
* Returns the minimum value allowed for this field.
* @returns {number}
*/
get min(): number;
/**
* Returns the maximum value allowed for this field.
* @returns {number}
*/
get max(): number;
/**
* Returns an array of allowed special characters for this field.
* @returns {string[]}
*/
get chars(): readonly string[];
/**
* Indicates whether this field has a "last" character.
* @returns {boolean}
*/
get hasLastChar(): boolean;
/**
* Indicates whether this field is a wildcard.
* @returns {boolean}
*/
get isWildcard(): boolean;
/**
* Returns an array of allowed values for this field.
* @returns {CronFieldType}
*/
get values(): CronFieldType;
/**
* Helper function to sort values in ascending order.
* @param {number | string} a - First value to compare
* @param {number | string} b - Second value to compare
* @returns {number} - A negative, zero, or positive value, depending on the sort order
*/
static sorter(a: number | string, b: number | string): number;
/**
* Serializes the field to an object.
* @todo This is really only for debugging, should it be removed?
* @returns {SerializedCronField}
*/
serialize(): SerializedCronField;
/**
* Validates the field values against the allowed range and special characters.
* @throws {Error} if validation fails
*/
validate(): void;
}