croner 10.0.0 → 10.0.2-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/options.d.ts DELETED
@@ -1,131 +0,0 @@
1
- import { CronDate } from "./date.ts";
2
- import type { CronMode } from "./pattern.ts";
3
- import type { Cron } from "./croner.ts";
4
- type CatchCallbackFn = (e: unknown, job: Cron) => void;
5
- type ProtectCallbackFn = (job: Cron) => void;
6
- /**
7
- * Options for configuring cron jobs.
8
- *
9
- * @interface
10
- */
11
- interface CronOptions<T = undefined> {
12
- /**
13
- * The name of the cron job. If provided, the job will be added to the
14
- * `scheduledJobs` array, allowing it to be accessed by name.
15
- */
16
- name?: string;
17
- /**
18
- * If true, the job will be paused initially.
19
- * @default false
20
- */
21
- paused?: boolean;
22
- /**
23
- * If true, the job will be stopped permanently.
24
- * @default false
25
- */
26
- kill?: boolean;
27
- /**
28
- * If true, errors thrown by the job function will be caught.
29
- * If a function is provided, it will be called with the error and the job instance.
30
- * @default false
31
- */
32
- catch?: boolean | CatchCallbackFn;
33
- /**
34
- * If true, the underlying timer will be unreferenced, allowing the Node.js
35
- * process to exit even if the job is still running.
36
- * @default false
37
- */
38
- unref?: boolean;
39
- /**
40
- * The maximum number of times the job will run.
41
- * @default Infinity
42
- */
43
- maxRuns?: number;
44
- /**
45
- * The minimum interval between job executions, in seconds.
46
- * @default 1
47
- */
48
- interval?: number;
49
- /**
50
- * If true, prevents the job from running if the previous execution is still in progress.
51
- * If a function is provided, it will be called if the job is blocked.
52
- * @default false
53
- */
54
- protect?: boolean | ProtectCallbackFn;
55
- /**
56
- * The date and time at which the job should start running.
57
- */
58
- startAt?: string | Date | CronDate<T>;
59
- /**
60
- * The date and time at which the job should stop running.
61
- */
62
- stopAt?: string | Date | CronDate<T>;
63
- /**
64
- * The timezone for the cron job.
65
- */
66
- timezone?: string;
67
- /**
68
- * The UTC offset for the cron job, in minutes.
69
- */
70
- utcOffset?: number;
71
- /**
72
- * If true, uses AND logic when combining day-of-month and day-of-week.
73
- * If false, uses OR logic for combining day-of-month and day-of-week (legacy behavior).
74
- * @default false
75
- */
76
- domAndDow?: boolean;
77
- /**
78
- * @deprecated Use domAndDow instead. This option will be removed in a future version.
79
- * If true, enables legacy mode (OR logic) for compatibility with older cron implementations.
80
- * Offset the scheduled date by a number of days.
81
- * Positive values shift the date forward, negative values shift it backward.
82
- * For example, dayOffset: -1 schedules the job one day before the pattern match.
83
- * @default 0
84
- */
85
- dayOffset?: number;
86
- /**
87
- * If true, enables legacy mode for compatibility with older cron implementations.
88
- * @default true
89
- */
90
- legacyMode?: boolean;
91
- /**
92
- * Specifies the cron pattern mode to use for parsing and execution.
93
- *
94
- * - "auto": Automatically detect pattern format (default behavior)
95
- * - "5-part": Traditional 5-field cron (minute-level precision, seconds forced to 0, years wildcarded)
96
- * - "6-part": Extended 6-field cron (second-level precision, years wildcarded)
97
- * - "7-part": Full 7-field cron (second-level and year-specific precision)
98
- * - "5-or-6-parts": Accept 5 or 6 field patterns (years wildcarded)
99
- * - "6-or-7-parts": Accept 6 or 7 field patterns (no additional constraints)
100
- *
101
- * @default "auto"
102
- */
103
- mode?: CronMode;
104
- /**
105
- * An optional context object that will be passed to the job function.
106
- */
107
- context?: T;
108
- /**
109
- * If true, enables alternative weekday numbering (Quartz mode).
110
- * In standard mode (false): Sunday=0, Monday=1, ..., Saturday=6
111
- * In Quartz mode (true): Sunday=1, Monday=2, ..., Saturday=7
112
- * @default false
113
- */
114
- alternativeWeekdays?: boolean;
115
- /**
116
- * If true, allows non-standard stepping formats for backward compatibility.
117
- * When false (default), only wildcard (*\/step) or range (min-max\/step) formats are allowed.
118
- * When true, allows numeric prefix formats like /10, 5/5, 30/30.
119
- * @default false
120
- */
121
- sloppyRanges?: boolean;
122
- }
123
- /**
124
- * Processes and validates cron options.
125
- *
126
- * @param options The cron options to handle.
127
- * @returns The processed and validated cron options.
128
- * @throws {Error} If any of the options are invalid.
129
- */
130
- declare function CronOptionsHandler<T = undefined>(options?: CronOptions<T>): CronOptions<T>;
131
- export { type CronOptions, CronOptionsHandler };
package/dist/pattern.d.ts DELETED
@@ -1,163 +0,0 @@
1
- /**
2
- * Cron pattern mode for controlling precision level
3
- */
4
- type CronMode = "auto" | "5-part" | "6-part" | "7-part" | "5-or-6-parts" | "6-or-7-parts";
5
- /**
6
- * Constants to represent different occurrences of a weekday in its month.
7
- * - `LAST_OCCURRENCE`: The last occurrence of a weekday.
8
- * - `ANY_OCCURRENCE`: Combines all individual weekday occurrence bitmasks, including the last.
9
- * - `OCCURRENCE_BITMASKS`: An array of bitmasks, with each index representing the respective occurrence of a weekday (0-indexed).
10
- */
11
- export declare const LAST_OCCURRENCE = 32;
12
- export declare const ANY_OCCURRENCE: number;
13
- export declare const OCCURRENCE_BITMASKS: number[];
14
- /**
15
- * Create a CronPattern instance from pattern string ('* * * * * *')
16
- * @constructor
17
- * @param {string} pattern - Input pattern
18
- * @param {string} timezone - Input timezone, used for '?'-substitution
19
- * @param {object} options - Cron options including mode
20
- */
21
- declare class CronPattern {
22
- pattern: string;
23
- timezone?: string;
24
- mode: CronMode;
25
- alternativeWeekdays: boolean;
26
- sloppyRanges: boolean;
27
- second: number[];
28
- minute: number[];
29
- hour: number[];
30
- day: number[];
31
- month: number[];
32
- dayOfWeek: number[];
33
- year: number[];
34
- lastDayOfMonth: boolean;
35
- lastWeekday: boolean;
36
- nearestWeekdays: number[];
37
- starDOM: boolean;
38
- starDOW: boolean;
39
- starYear: boolean;
40
- useAndLogic: boolean;
41
- constructor(pattern: string, timezone?: string, options?: {
42
- mode?: CronMode;
43
- alternativeWeekdays?: boolean;
44
- sloppyRanges?: boolean;
45
- });
46
- /**
47
- * Parse current pattern, will throw on any type of failure
48
- * @private
49
- */
50
- private parse;
51
- /**
52
- * Convert current part (seconds/minutes etc) to an array of 1 or 0 depending on if the part is about to trigger a run or not.
53
- */
54
- private partToArray;
55
- /**
56
- * After converting JAN-DEC, SUN-SAT only 0-9 * , / - are allowed, throw if anything else pops up
57
- * @throws On error
58
- */
59
- private throwAtIllegalCharacters;
60
- /**
61
- * Nothing but a number, potentially with a modifier, left - handle that
62
- *
63
- * @param conf Current part, expected to be a number, as a string
64
- * @param type One of "seconds", "minutes" etc
65
- * @param valueIndexOffset -1 for day of month, and month, as they start at 1. 0 for seconds, hours, minutes
66
- */
67
- private handleNumber;
68
- /**
69
- * Set a specific value for a specific part of the CronPattern.
70
- *
71
- * @param part The specific part of the CronPattern, e.g., "second", "minute", etc.
72
- * @param index The index to modify.
73
- * @param value The value to set, typically 0 or 1, in case of "nth weekday" it will be the weekday number used for further processing
74
- */
75
- private setPart;
76
- /**
77
- * Validates that a parsed number is not NaN.
78
- * Throws a TypeError with a descriptive message if the value is NaN.
79
- *
80
- * @param value - The value to validate
81
- * @param errorMessage - The error message to throw if validation fails
82
- * @throws {TypeError} If the value is NaN
83
- * @private
84
- */
85
- private validateNotNaN;
86
- /**
87
- * Validates that a range is valid (lower <= upper) and that steps are valid (> 0 and <= array length).
88
- *
89
- * @param lower - Lower bound of range
90
- * @param upper - Upper bound of range
91
- * @param steps - Optional step value to validate
92
- * @param type - The type of pattern part being validated
93
- * @param conf - The original configuration string for error messages
94
- * @throws {TypeError} If validation fails
95
- * @private
96
- */
97
- private validateRange;
98
- /**
99
- * Take care of ranges with stepping (e.g. 3-23/5)
100
- *
101
- * @param conf Current part, expected to be a string like 3-23/5
102
- * @param type One of "seconds", "minutes" etc
103
- * @param valueIndexOffset -1 for day of month, and month, as they start at 1. 0 for seconds, hours, minutes
104
- */
105
- private handleRangeWithStepping;
106
- private extractNth;
107
- /**
108
- * Take care of ranges (e.g. 1-20)
109
- *
110
- * @param conf - Current part, expected to be a string like 1-20, can contain L for last
111
- * @param type - One of "seconds", "minutes" etc
112
- * @param valueIndexOffset - -1 for day of month, and month, as they start at 1. 0 for seconds, hours, minutes
113
- */
114
- private handleRange;
115
- /**
116
- * Handle stepping (e.g. * / 14)
117
- *
118
- * @param conf Current part, expected to be a string like * /20 (without the space)
119
- * @param type One of "seconds", "minutes" etc
120
- */
121
- private handleStepping;
122
- /**
123
- * Replace day name with day numbers
124
- *
125
- * @param conf Current part, expected to be a string that might contain sun,mon etc.
126
- *
127
- * @returns Conf with 0 instead of sun etc.
128
- */
129
- private replaceAlphaDays;
130
- /**
131
- * Replace day name with day numbers (Quartz mode)
132
- * In Quartz mode: Sunday=1, Monday=2, ..., Saturday=7
133
- *
134
- * @param conf Current part, expected to be a string that might contain sun,mon etc.
135
- *
136
- * @returns Conf with Quartz-style numbering
137
- */
138
- private replaceAlphaDaysQuartz;
139
- /**
140
- * Replace month name with month numbers
141
- *
142
- * @param conf Current part, expected to be a string that might contain jan,feb etc.
143
- *
144
- * @returns conf with 0 instead of sun etc.
145
- */
146
- private replaceAlphaMonths;
147
- /**
148
- * Replace nicknames with actual cron patterns
149
- *
150
- * @param pattern Pattern, may contain nicknames, or not
151
- *
152
- * @returns Pattern, with cron expression insted of nicknames
153
- */
154
- private handleNicknames;
155
- /**
156
- * Handle the nth weekday of the month logic using hash sign (e.g. FRI#2 for the second Friday of the month)
157
- *
158
- * @param index Weekday, example: 5 for friday
159
- * @param nthWeekday bitmask, 2 (0x00010) for 2nd friday, 31 (ANY_OCCURRENCE, 0b100000) for any day
160
- */
161
- private setNthWeekdayOfMonth;
162
- }
163
- export { type CronMode, CronPattern };
package/dist/utils.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import type { CronCallback } from "./croner.ts";
2
- /**
3
- * Helper function to check if a variable is a function.
4
- *
5
- * @param v The variable to check.
6
- * @returns True if the variable is a function, false otherwise.
7
- * @private
8
- */
9
- declare function isFunction(v: unknown): boolean;
10
- /**
11
- * Type guard to check if a variable is a valid CronCallback function.
12
- *
13
- * @param v The variable to check.
14
- * @returns Type predicate indicating if the variable is a CronCallback.
15
- * @private
16
- */
17
- export declare function isCronCallback(v: unknown): v is CronCallback;
18
- /**
19
- * Helper function to unref a timer in both Deno and Node.js.
20
- *
21
- * @param timer The timer to unref.
22
- * @private
23
- */
24
- declare function unrefTimer(timer: NodeJS.Timeout | number): void;
25
- export { isFunction, unrefTimer };