croner 3.0.40 → 3.0.44
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/README.md +211 -211
- package/dist/croner.min.js +1 -1
- package/dist/croner.min.mjs +1 -1
- package/dist-legacy/croner.cjs +1 -1
- package/package.json +1 -1
- package/src/croner.js +84 -455
- package/src/date.js +214 -0
- package/src/pattern.js +202 -0
- package/src/timezone.js +12 -0
- package/test/{suite.cjs → src/suite.cjs} +3 -1
- package/test/test.croner.js +30 -0
- package/test/test.dist.legacy.cjs +1 -1
- package/test/test.dist.module.js +1 -1
- package/types/croner.d.ts +28 -45
- package/types/date.d.ts +54 -0
- package/types/pattern.d.ts +43 -0
- package/types/timezone.d.ts +9 -0
package/README.md
CHANGED
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
# Croner
|
|
2
|
-
|
|
3
|
-
[](https://travis-ci.org/Hexagon/croner) [](https://badge.fury.io/js/croner) [](https://www.codacy.com/gh/Hexagon/croner/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Hexagon/croner&utm_campaign=Badge_Grade)
|
|
4
|
-
[](https://github.com/Hexagon/croner/blob/master/LICENSE) [](https://www.jsdelivr.com/package/npm/croner)
|
|
5
|
-
|
|
6
|
-
Pure JavaScript minimal isomorphic cron parser and scheduler. Or simply speaking - setInterval on steroids.
|
|
7
|
-
|
|
8
|
-
Documented with [JSDoc](https://jsdoc.app/) for intellisense, and include [TypeScript](https://www.typescriptlang.org/) typings.
|
|
9
|
-
|
|
10
|
-
```html
|
|
11
|
-
<script src="https://cdn.jsdelivr.net/npm/croner@3/dist/croner.min.js"></script>
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
```javascript
|
|
15
|
-
// Run a function each second
|
|
16
|
-
Cron('* * * * * *', function () {
|
|
17
|
-
console.log('This will run every second');
|
|
18
|
-
});
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Installation
|
|
22
|
-
|
|
23
|
-
### Manual
|
|
24
|
-
|
|
25
|
-
* Download latest [zipball](http://github.com/Hexagon/croner/zipball/master/)
|
|
26
|
-
* Unpack
|
|
27
|
-
* Grab ```croner.min.js``` ([UMD](https://github.com/umdjs/umd)) or ```croner.min.mjs``` ([ES-module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)) from the [dist/](/dist) folder
|
|
28
|
-
|
|
29
|
-
### Node.js
|
|
30
|
-
|
|
31
|
-
```npm install croner --save```
|
|
32
|
-
|
|
33
|
-
```javascript
|
|
34
|
-
// ESM Import
|
|
35
|
-
import Cron from "croner";
|
|
36
|
-
|
|
37
|
-
// ... or
|
|
38
|
-
|
|
39
|
-
// CommonJS Require
|
|
40
|
-
|
|
41
|
-
const Cron = require("croner");
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### CDN
|
|
45
|
-
|
|
46
|
-
To use as a [UMD](https://github.com/umdjs/umd)-module (stand alone, [RequireJS](https://requirejs.org/) etc.)
|
|
47
|
-
|
|
48
|
-
```html
|
|
49
|
-
<script src="https://cdn.jsdelivr.net/npm/croner@3/dist/croner.min.js"></script>
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
To use as a [ES-module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
|
|
53
|
-
|
|
54
|
-
```html
|
|
55
|
-
<script type="module">
|
|
56
|
-
import Cron from "https://cdn.jsdelivr.net/npm/croner@3/dist/croner.min.mjs";
|
|
57
|
-
|
|
58
|
-
// ... see usage section ...
|
|
59
|
-
</script>
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
... or a ES-module with [import-map](https://github.com/WICG/import-maps)
|
|
63
|
-
```html
|
|
64
|
-
<script type="importmap">
|
|
65
|
-
{
|
|
66
|
-
"imports": {
|
|
67
|
-
"croner": "https://cdn.jsdelivr.net/npm/croner@3/dist/croner.min.mjs"
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
</script>
|
|
71
|
-
<script type="module">
|
|
72
|
-
import Cron from 'croner';
|
|
73
|
-
|
|
74
|
-
// ... see usage section ...
|
|
75
|
-
</script>
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## Examples
|
|
79
|
-
|
|
80
|
-
### Minimalist scheduling
|
|
81
|
-
```javascript
|
|
82
|
-
// Run a function each second
|
|
83
|
-
Cron('* * * * * *', function () {
|
|
84
|
-
console.log('This will run every second');
|
|
85
|
-
});
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Minimalist scheduling with stepping
|
|
89
|
-
```javascript
|
|
90
|
-
// Run a function every fifth second
|
|
91
|
-
Cron('*/5 * * * * *', function () {
|
|
92
|
-
console.log('This will run every fifth second');
|
|
93
|
-
});
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### Minimalist scheduling with range
|
|
97
|
-
```javascript
|
|
98
|
-
// Run a function the first five seconds of a minute
|
|
99
|
-
Cron('0-4 * * * * *', function () {
|
|
100
|
-
console.log('This will run the first five seconds every minute');
|
|
101
|
-
});
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### Minimalist scheduling with options
|
|
105
|
-
```javascript
|
|
106
|
-
// Run a function each second, limit to five runs
|
|
107
|
-
Cron('* * * * * *', { maxRuns: 5 }, function () {
|
|
108
|
-
console.log('This will run each second, but only five times.');
|
|
109
|
-
});
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### Minimalist scheduling with job controls
|
|
113
|
-
```javascript
|
|
114
|
-
// Run a function each second, get reference to job
|
|
115
|
-
var job = Cron('* * * * * *', function () {
|
|
116
|
-
console.log('This will run each second.');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// Pause job
|
|
120
|
-
job.pause();
|
|
121
|
-
|
|
122
|
-
// Resume job
|
|
123
|
-
job.resume();
|
|
124
|
-
|
|
125
|
-
// Stop job
|
|
126
|
-
job.stop();
|
|
127
|
-
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### Basic scheduling
|
|
131
|
-
```javascript
|
|
132
|
-
|
|
133
|
-
// Run every minute
|
|
134
|
-
var scheduler = Cron('0 * * * * *');
|
|
135
|
-
|
|
136
|
-
scheduler.schedule(function() {
|
|
137
|
-
console.log('This will run every minute');
|
|
138
|
-
});
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### Scheduling with options
|
|
142
|
-
```javascript
|
|
143
|
-
|
|
144
|
-
// Run every minute
|
|
145
|
-
var scheduler = Cron('0 * * * * *');
|
|
146
|
-
|
|
147
|
-
// Schedule with options (all options are optional)
|
|
148
|
-
scheduler.schedule({ maxRuns: 5 }, function() {
|
|
149
|
-
console.log('This will run every minute.');
|
|
150
|
-
});
|
|
151
|
-
```
|
|
152
|
-
### Scheduling with job controls
|
|
153
|
-
```javascript
|
|
154
|
-
|
|
155
|
-
// Run every minute
|
|
156
|
-
var scheduler = Cron('0 * * * * *');
|
|
157
|
-
|
|
158
|
-
// Schedule with options (all options are optional)
|
|
159
|
-
var job = scheduler.schedule({ maxRuns: 5 }, function() {
|
|
160
|
-
console.log('This will run every minute.');
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// Pause job
|
|
164
|
-
job.pause();
|
|
165
|
-
|
|
166
|
-
// Resume job
|
|
167
|
-
job.resume();
|
|
168
|
-
|
|
169
|
-
// Stop job
|
|
170
|
-
job.stop();
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## Full API
|
|
174
|
-
```javascript
|
|
175
|
-
|
|
176
|
-
var o = Cron( <string pattern> [, <object options>] [, <function callback> ] );
|
|
177
|
-
```
|
|
178
|
-
```javascript
|
|
179
|
-
// If Cron is initialized without a scheduled function, cron itself is returned
|
|
180
|
-
// and the following member functions is available.
|
|
181
|
-
o.next( [ <date previous> ] );
|
|
182
|
-
o.msToNext();
|
|
183
|
-
o.previous();
|
|
184
|
-
|
|
185
|
-
// If Cron is initialized _with_ a scheduled function, the job is retured instead.
|
|
186
|
-
// Otherwise you get a reference to the job when scheduling a new job.
|
|
187
|
-
var job = o.schedule( [ { startAt: <date>, stopAt: <date>, maxRuns: <integer> } ,] callback);
|
|
188
|
-
|
|
189
|
-
// These self-explanatory functions is available to control the job
|
|
190
|
-
job.pause();
|
|
191
|
-
job.resume();
|
|
192
|
-
job.stop();
|
|
193
|
-
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
## Pattern
|
|
197
|
-
|
|
198
|
-
```
|
|
199
|
-
┌──────────────── (optional) second (0 - 59)
|
|
200
|
-
│ ┌────────────── minute (0 - 59)
|
|
201
|
-
│ │ ┌──────────── hour (0 - 23)
|
|
202
|
-
│ │ │ ┌────────── day of month (1 - 31)
|
|
203
|
-
│ │ │ │ ┌──────── month (1 - 12)
|
|
204
|
-
│ │ │ │ │ ┌────── day of week (0 - 6)
|
|
205
|
-
│ │ │ │ │ │ (0 to 6 are Sunday to Saturday; 7 is Sunday, the same as 0)
|
|
206
|
-
│ │ │ │ │ │
|
|
207
|
-
* * * * * *
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
## License
|
|
211
|
-
|
|
1
|
+
# Croner
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/Hexagon/croner) [](https://badge.fury.io/js/croner) [](https://www.codacy.com/gh/Hexagon/croner/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Hexagon/croner&utm_campaign=Badge_Grade)
|
|
4
|
+
[](https://github.com/Hexagon/croner/blob/master/LICENSE) [](https://www.jsdelivr.com/package/npm/croner)
|
|
5
|
+
|
|
6
|
+
Pure JavaScript minimal isomorphic cron parser and scheduler. Or simply speaking - setInterval on steroids.
|
|
7
|
+
|
|
8
|
+
Documented with [JSDoc](https://jsdoc.app/) for intellisense, and include [TypeScript](https://www.typescriptlang.org/) typings.
|
|
9
|
+
|
|
10
|
+
```html
|
|
11
|
+
<script src="https://cdn.jsdelivr.net/npm/croner@3/dist/croner.min.js"></script>
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```javascript
|
|
15
|
+
// Run a function each second
|
|
16
|
+
Cron('* * * * * *', function () {
|
|
17
|
+
console.log('This will run every second');
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
### Manual
|
|
24
|
+
|
|
25
|
+
* Download latest [zipball](http://github.com/Hexagon/croner/zipball/master/)
|
|
26
|
+
* Unpack
|
|
27
|
+
* Grab ```croner.min.js``` ([UMD](https://github.com/umdjs/umd)) or ```croner.min.mjs``` ([ES-module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)) from the [dist/](/dist) folder
|
|
28
|
+
|
|
29
|
+
### Node.js
|
|
30
|
+
|
|
31
|
+
```npm install croner --save```
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
// ESM Import
|
|
35
|
+
import Cron from "croner";
|
|
36
|
+
|
|
37
|
+
// ... or
|
|
38
|
+
|
|
39
|
+
// CommonJS Require
|
|
40
|
+
|
|
41
|
+
const Cron = require("croner");
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### CDN
|
|
45
|
+
|
|
46
|
+
To use as a [UMD](https://github.com/umdjs/umd)-module (stand alone, [RequireJS](https://requirejs.org/) etc.)
|
|
47
|
+
|
|
48
|
+
```html
|
|
49
|
+
<script src="https://cdn.jsdelivr.net/npm/croner@3/dist/croner.min.js"></script>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
To use as a [ES-module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<script type="module">
|
|
56
|
+
import Cron from "https://cdn.jsdelivr.net/npm/croner@3/dist/croner.min.mjs";
|
|
57
|
+
|
|
58
|
+
// ... see usage section ...
|
|
59
|
+
</script>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
... or a ES-module with [import-map](https://github.com/WICG/import-maps)
|
|
63
|
+
```html
|
|
64
|
+
<script type="importmap">
|
|
65
|
+
{
|
|
66
|
+
"imports": {
|
|
67
|
+
"croner": "https://cdn.jsdelivr.net/npm/croner@3/dist/croner.min.mjs"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
</script>
|
|
71
|
+
<script type="module">
|
|
72
|
+
import Cron from 'croner';
|
|
73
|
+
|
|
74
|
+
// ... see usage section ...
|
|
75
|
+
</script>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Examples
|
|
79
|
+
|
|
80
|
+
### Minimalist scheduling
|
|
81
|
+
```javascript
|
|
82
|
+
// Run a function each second
|
|
83
|
+
Cron('* * * * * *', function () {
|
|
84
|
+
console.log('This will run every second');
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Minimalist scheduling with stepping and custom timezone
|
|
89
|
+
```javascript
|
|
90
|
+
// Run a function every fifth second
|
|
91
|
+
Cron('*/5 * * * * *', { timezone: 'Europe/Stockholm' } function () {
|
|
92
|
+
console.log('This will run every fifth second');
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Minimalist scheduling with range
|
|
97
|
+
```javascript
|
|
98
|
+
// Run a function the first five seconds of a minute
|
|
99
|
+
Cron('0-4 * * * * *', function () {
|
|
100
|
+
console.log('This will run the first five seconds every minute');
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Minimalist scheduling with options
|
|
105
|
+
```javascript
|
|
106
|
+
// Run a function each second, limit to five runs
|
|
107
|
+
Cron('* * * * * *', { maxRuns: 5 }, function () {
|
|
108
|
+
console.log('This will run each second, but only five times.');
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Minimalist scheduling with job controls
|
|
113
|
+
```javascript
|
|
114
|
+
// Run a function each second, get reference to job
|
|
115
|
+
var job = Cron('* * * * * *', function () {
|
|
116
|
+
console.log('This will run each second.');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// Pause job
|
|
120
|
+
job.pause();
|
|
121
|
+
|
|
122
|
+
// Resume job
|
|
123
|
+
job.resume();
|
|
124
|
+
|
|
125
|
+
// Stop job
|
|
126
|
+
job.stop();
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Basic scheduling
|
|
131
|
+
```javascript
|
|
132
|
+
|
|
133
|
+
// Run every minute
|
|
134
|
+
var scheduler = Cron('0 * * * * *');
|
|
135
|
+
|
|
136
|
+
scheduler.schedule(function() {
|
|
137
|
+
console.log('This will run every minute');
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Scheduling with options
|
|
142
|
+
```javascript
|
|
143
|
+
|
|
144
|
+
// Run every minute
|
|
145
|
+
var scheduler = Cron('0 * * * * *');
|
|
146
|
+
|
|
147
|
+
// Schedule with options (all options are optional)
|
|
148
|
+
scheduler.schedule({ maxRuns: 5 }, function() {
|
|
149
|
+
console.log('This will run every minute.');
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
### Scheduling with job controls
|
|
153
|
+
```javascript
|
|
154
|
+
|
|
155
|
+
// Run every minute
|
|
156
|
+
var scheduler = Cron('0 * * * * *');
|
|
157
|
+
|
|
158
|
+
// Schedule with options (all options are optional)
|
|
159
|
+
var job = scheduler.schedule({ maxRuns: 5 }, function() {
|
|
160
|
+
console.log('This will run every minute.');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Pause job
|
|
164
|
+
job.pause();
|
|
165
|
+
|
|
166
|
+
// Resume job
|
|
167
|
+
job.resume();
|
|
168
|
+
|
|
169
|
+
// Stop job
|
|
170
|
+
job.stop();
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Full API
|
|
174
|
+
```javascript
|
|
175
|
+
|
|
176
|
+
var o = Cron( <string pattern> [, <object options>] [, <function callback> ] );
|
|
177
|
+
```
|
|
178
|
+
```javascript
|
|
179
|
+
// If Cron is initialized without a scheduled function, cron itself is returned
|
|
180
|
+
// and the following member functions is available.
|
|
181
|
+
o.next( [ <date previous> ] );
|
|
182
|
+
o.msToNext();
|
|
183
|
+
o.previous();
|
|
184
|
+
|
|
185
|
+
// If Cron is initialized _with_ a scheduled function, the job is retured instead.
|
|
186
|
+
// Otherwise you get a reference to the job when scheduling a new job.
|
|
187
|
+
var job = o.schedule( [ { startAt: <date|string>, stopAt: <date|string>, maxRuns: <integer>, timezone: <string> } ,] callback);
|
|
188
|
+
|
|
189
|
+
// These self-explanatory functions is available to control the job
|
|
190
|
+
job.pause();
|
|
191
|
+
job.resume();
|
|
192
|
+
job.stop();
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Pattern
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
┌──────────────── (optional) second (0 - 59)
|
|
200
|
+
│ ┌────────────── minute (0 - 59)
|
|
201
|
+
│ │ ┌──────────── hour (0 - 23)
|
|
202
|
+
│ │ │ ┌────────── day of month (1 - 31)
|
|
203
|
+
│ │ │ │ ┌──────── month (1 - 12)
|
|
204
|
+
│ │ │ │ │ ┌────── day of week (0 - 6)
|
|
205
|
+
│ │ │ │ │ │ (0 to 6 are Sunday to Saturday; 7 is Sunday, the same as 0)
|
|
206
|
+
│ │ │ │ │ │
|
|
207
|
+
* * * * * *
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
212
|
MIT
|
package/dist/croner.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Cron=e():t.Cron=e()}(this,(function(){return(()=>{"use strict";var t={d:(e,
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Cron=e():t.Cron=e()}(this,(function(){return(()=>{"use strict";var t={d:(e,r)=>{for(var s in r)t.o(r,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:r[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{default:()=>i});function r(t,e){if(this.timezone=e,t&&t instanceof Date)this.fromDate(t);else if(void 0===t)this.fromDate(new Date);else if(t&&"string"==typeof t)this.fromString(t);else{if(!(t instanceof r))throw new TypeError("CronDate: Invalid type passed as parameter to CronDate constructor");this.fromCronDate(t)}}function s(t){this.pattern=t,this.seconds=Array(60).fill(0),this.minutes=Array(60).fill(0),this.hours=Array(24).fill(0),this.days=Array(31).fill(0),this.months=Array(12).fill(0),this.daysOfWeek=Array(8).fill(0),this.parse()}r.prototype.fromDate=function(t){let e=t.getTime();this.timezone&&(t=function(t,e){return new Date(t.toLocaleString("en-US",{timeZone:e}))}(t,this.timezone));let r=t.getTime();this.UTCmsOffset=r-e,this.milliseconds=t.getMilliseconds(),this.seconds=t.getSeconds(),this.minutes=t.getMinutes(),this.hours=t.getHours(),this.days=t.getDate(),this.months=t.getMonth(),this.years=t.getFullYear()},r.prototype.fromCronDate=function(t){this.UTCmsOffset=t.UTCmsOffset,this.milliseconds=t.milliseconds,this.seconds=t.seconds,this.minutes=t.minutes,this.hours=t.hours,this.days=t.days,this.months=t.months,this.years=t.years},r.prototype.fromString=function(t){let e=Date.parse(t);if(isNaN(e))throw new TypeError("CronDate: Provided string value for CronDate could not be parsed as date.");this.fromDate(new Date(e))},r.prototype.increment=function(t){this.seconds+=1,this.milliseconds=0;let e=this,r=function(t,r,s,o){for(let n=void 0===o?e[t]+s:0+s;n<r[t].length;n++)if(r[t][n])return e[t]=n-s,!0;return!1},s=[["seconds","minutes",0],["minutes","hours",0],["hours","days",0],["days","months",-1],["months","years",0]],o=0;for(;o<5;){if(!r(s[o][0],t,s[o][2]))for(this[s[o][1]]++;o>=0;)r(s[o][0],t,s[o][2],0),o--;o++}for(;!t.daysOfWeek[this.getDate().getDay()];)this.days+=1;return this},r.prototype.getDate=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,this.milliseconds-this.UTCmsOffset)},r.prototype.getTime=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,this.milliseconds-this.UTCmsOffset).getTime()},s.prototype.parse=function(){if("string"!=typeof this.pattern&&this.pattern.constructor!==String)throw new TypeError("CronPattern: Pattern has to be of type string.");let t,e,r,s,o,n=this.pattern.trim().replace(/\s+/g," ").split(" "),i=/[^/*0-9,-]+/;if(n.length<5||n.length>6)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exacly five or six space separated parts required.");for(5===n.length&&n.unshift("0"),e=0;e<n.length;e++)if(t=n[e].trim(),i.test(t))throw new TypeError("CronPattern: configuration entry "+(e+1)+" ("+t+") contains illegal characters.");if(r="*"!==n[4],s="*"!==n[5],o="*"!==n[3],s&&(r||o))throw new TypeError("CronPattern: configuration invalid, you can not combine month/date with day of week.");this.partToArray("seconds",n[0],0),this.partToArray("minutes",n[1],0),this.partToArray("hours",n[2],0),this.partToArray("days",n[3],-1),this.partToArray("months",n[4],-1),this.partToArray("daysOfWeek",n[5],0),this.daysOfWeek[7]&&(this.daysOfWeek[0]=1)},s.prototype.partToArray=function(t,e,r){let s,o,n,i,a,h=this[t];if("*"!==e)if(o=e.split(","),o.length>1)for(s=0;s<o.length;s++)this.partToArray(t,o[s],r);else if(-1!==e.indexOf("-")){if(o=e.split("-"),2!==o.length)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");if(n=parseInt(o[0],10)+r,i=parseInt(o[1],10)+r,isNaN(n))throw new TypeError("CronPattern: Syntax error, illegal lower range (NaN)");if(isNaN(i))throw new TypeError("CronPattern: Syntax error, illegal upper range (NaN)");if(n<0||i>=h.length)throw new TypeError("CronPattern: Value out of range: '"+e+"'");if(n>i)throw new TypeError("CronPattern: From value is larger than to value: '"+e+"'");for(s=n;s<=i;s++)h[s+r]=1}else if(-1!==e.indexOf("/")){if(o=e.split("/"),2!==o.length)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if("*"!==o[0])throw new TypeError("CronPattern: Syntax error, left part of / needs to be * : '"+e+"'");if(a=parseInt(o[1],10),isNaN(a))throw new TypeError("CronPattern: Syntax error, illegal stepping: (NaN)");if(0===a)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(a>h.length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+h.length+")");for(s=0;s<h.length;s+=a)h[s+r]=1}else{if(s=parseInt(e,10)+r,s<0||s>=h.length)throw new TypeError("CronPattern: "+t+" value out of range: '"+e+"'");h[s]=1}else for(s=0;s<h.length;s++)h[s]=1};const o=Math.pow(2,31)-1;function n(t,e,r){let o=this;return this instanceof n?(o.pattern=new s(t),o.schedulerDefaults={maxRuns:1/0,kill:!1},"function"==typeof e&&(r=e,e={}),o.opts=o.validateOpts(e||{}),void 0===r?o:this.schedule(e,r)):new n(t,e,r)}n.prototype.next=function(t){let e=this._next(t);return e?e.getDate():null},n.prototype.previous=function(){return this.opts.previous?this.opts.previous.getDate():null},n.prototype._next=function(t){t=new r(t,this.opts.timezone),this.opts.startAt&&t&&t.getTime()<this.opts.startAt.getTime()&&(t=new r(this.opts.startAt,this.opts.timezone));let e=new r(t,this.opts.timezone).increment(this.pattern);return this.opts.maxRuns<=0||this.opts.kill||this.opts.stopAt&&e.getTime()>=this.opts.stopAt.getTime()?null:e},n.prototype.validateOpts=function(t){return t.startAt&&(t.startAt=new r(t.startAt,t.timezone)),t.stopAt&&(t.stopAt=new r(t.stopAt,t.timezone)),t},n.prototype.msToNext=function(t){t=t||new r(void 0,this.opts.timezone);let e=this._next(t);return e?e.getTime()-t.getTime():null},n.prototype.schedule=function(t,e){e||(e=t,t=this.opts),t.paused=void 0!==t.paused&&t.paused,t.kill=t.kill||this.schedulerDefaults.kill,t.maxRuns||0===t.maxRuns||(t.maxRuns=this.schedulerDefaults.maxRuns),this.opts=this.validateOpts(t||{}),this._schedule(t,e)},n.prototype._schedule=function(t,e){let s,n=this,i=n.maxDelay||o;if(s=this.msToNext(n.opts.previous),null!==s)return s>i&&(s=i),n.opts.currentTimeout=setTimeout((function(){s!==i&&(n.opts.paused||(n.opts.maxRuns--,e()),n.opts.previous=new r(n.opts.previous,n.opts.timezone)),n._schedule(n.opts,e)}),s),{stop:function(){n.opts.kill=!0,n.opts.currentTimeout&&clearTimeout(n.opts.currentTimeout)},pause:function(){return(n.opts.paused=!0)&&!n.opts.kill},resume:function(){return!(n.opts.paused=!1)&&!n.opts.kill}}};const i=n;return e.default})()}));
|
package/dist/croner.min.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t={d:(e,
|
|
1
|
+
var t={d:(e,r)=>{for(var s in r)t.o(r,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:r[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{P:()=>n,Z:()=>i});function r(t,e){if(this.timezone=e,t&&t instanceof Date)this.fromDate(t);else if(void 0===t)this.fromDate(new Date);else if(t&&"string"==typeof t)this.fromString(t);else{if(!(t instanceof r))throw new TypeError("CronDate: Invalid type passed as parameter to CronDate constructor");this.fromCronDate(t)}}function s(t){this.pattern=t,this.seconds=Array(60).fill(0),this.minutes=Array(60).fill(0),this.hours=Array(24).fill(0),this.days=Array(31).fill(0),this.months=Array(12).fill(0),this.daysOfWeek=Array(8).fill(0),this.parse()}r.prototype.fromDate=function(t){let e=t.getTime();this.timezone&&(t=function(t,e){return new Date(t.toLocaleString("en-US",{timeZone:e}))}(t,this.timezone));let r=t.getTime();this.UTCmsOffset=r-e,this.milliseconds=t.getMilliseconds(),this.seconds=t.getSeconds(),this.minutes=t.getMinutes(),this.hours=t.getHours(),this.days=t.getDate(),this.months=t.getMonth(),this.years=t.getFullYear()},r.prototype.fromCronDate=function(t){this.UTCmsOffset=t.UTCmsOffset,this.milliseconds=t.milliseconds,this.seconds=t.seconds,this.minutes=t.minutes,this.hours=t.hours,this.days=t.days,this.months=t.months,this.years=t.years},r.prototype.fromString=function(t){let e=Date.parse(t);if(isNaN(e))throw new TypeError("CronDate: Provided string value for CronDate could not be parsed as date.");this.fromDate(new Date(e))},r.prototype.increment=function(t){this.seconds+=1,this.milliseconds=0;let e=this,r=function(t,r,s,o){for(let n=void 0===o?e[t]+s:0+s;n<r[t].length;n++)if(r[t][n])return e[t]=n-s,!0;return!1},s=[["seconds","minutes",0],["minutes","hours",0],["hours","days",0],["days","months",-1],["months","years",0]],o=0;for(;o<5;){if(!r(s[o][0],t,s[o][2]))for(this[s[o][1]]++;o>=0;)r(s[o][0],t,s[o][2],0),o--;o++}for(;!t.daysOfWeek[this.getDate().getDay()];)this.days+=1;return this},r.prototype.getDate=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,this.milliseconds-this.UTCmsOffset)},r.prototype.getTime=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,this.milliseconds-this.UTCmsOffset).getTime()},s.prototype.parse=function(){if("string"!=typeof this.pattern&&this.pattern.constructor!==String)throw new TypeError("CronPattern: Pattern has to be of type string.");let t,e,r,s,o,n=this.pattern.trim().replace(/\s+/g," ").split(" "),i=/[^/*0-9,-]+/;if(n.length<5||n.length>6)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exacly five or six space separated parts required.");for(5===n.length&&n.unshift("0"),e=0;e<n.length;e++)if(t=n[e].trim(),i.test(t))throw new TypeError("CronPattern: configuration entry "+(e+1)+" ("+t+") contains illegal characters.");if(r="*"!==n[4],s="*"!==n[5],o="*"!==n[3],s&&(r||o))throw new TypeError("CronPattern: configuration invalid, you can not combine month/date with day of week.");this.partToArray("seconds",n[0],0),this.partToArray("minutes",n[1],0),this.partToArray("hours",n[2],0),this.partToArray("days",n[3],-1),this.partToArray("months",n[4],-1),this.partToArray("daysOfWeek",n[5],0),this.daysOfWeek[7]&&(this.daysOfWeek[0]=1)},s.prototype.partToArray=function(t,e,r){let s,o,n,i,a,h=this[t];if("*"!==e)if(o=e.split(","),o.length>1)for(s=0;s<o.length;s++)this.partToArray(t,o[s],r);else if(-1!==e.indexOf("-")){if(o=e.split("-"),2!==o.length)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");if(n=parseInt(o[0],10)+r,i=parseInt(o[1],10)+r,isNaN(n))throw new TypeError("CronPattern: Syntax error, illegal lower range (NaN)");if(isNaN(i))throw new TypeError("CronPattern: Syntax error, illegal upper range (NaN)");if(n<0||i>=h.length)throw new TypeError("CronPattern: Value out of range: '"+e+"'");if(n>i)throw new TypeError("CronPattern: From value is larger than to value: '"+e+"'");for(s=n;s<=i;s++)h[s+r]=1}else if(-1!==e.indexOf("/")){if(o=e.split("/"),2!==o.length)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if("*"!==o[0])throw new TypeError("CronPattern: Syntax error, left part of / needs to be * : '"+e+"'");if(a=parseInt(o[1],10),isNaN(a))throw new TypeError("CronPattern: Syntax error, illegal stepping: (NaN)");if(0===a)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(a>h.length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+h.length+")");for(s=0;s<h.length;s+=a)h[s+r]=1}else{if(s=parseInt(e,10)+r,s<0||s>=h.length)throw new TypeError("CronPattern: "+t+" value out of range: '"+e+"'");h[s]=1}else for(s=0;s<h.length;s++)h[s]=1};const o=Math.pow(2,31)-1;function n(t,e,r){let o=this;return this instanceof n?(o.pattern=new s(t),o.schedulerDefaults={maxRuns:1/0,kill:!1},"function"==typeof e&&(r=e,e={}),o.opts=o.validateOpts(e||{}),void 0===r?o:this.schedule(e,r)):new n(t,e,r)}n.prototype.next=function(t){let e=this._next(t);return e?e.getDate():null},n.prototype.previous=function(){return this.opts.previous?this.opts.previous.getDate():null},n.prototype._next=function(t){t=new r(t,this.opts.timezone),this.opts.startAt&&t&&t.getTime()<this.opts.startAt.getTime()&&(t=new r(this.opts.startAt,this.opts.timezone));let e=new r(t,this.opts.timezone).increment(this.pattern);return this.opts.maxRuns<=0||this.opts.kill||this.opts.stopAt&&e.getTime()>=this.opts.stopAt.getTime()?null:e},n.prototype.validateOpts=function(t){return t.startAt&&(t.startAt=new r(t.startAt,t.timezone)),t.stopAt&&(t.stopAt=new r(t.stopAt,t.timezone)),t},n.prototype.msToNext=function(t){t=t||new r(void 0,this.opts.timezone);let e=this._next(t);return e?e.getTime()-t.getTime():null},n.prototype.schedule=function(t,e){e||(e=t,t=this.opts),t.paused=void 0!==t.paused&&t.paused,t.kill=t.kill||this.schedulerDefaults.kill,t.maxRuns||0===t.maxRuns||(t.maxRuns=this.schedulerDefaults.maxRuns),this.opts=this.validateOpts(t||{}),this._schedule(t,e)},n.prototype._schedule=function(t,e){let s,n=this,i=n.maxDelay||o;if(s=this.msToNext(n.opts.previous),null!==s)return s>i&&(s=i),n.opts.currentTimeout=setTimeout((function(){s!==i&&(n.opts.paused||(n.opts.maxRuns--,e()),n.opts.previous=new r(n.opts.previous,n.opts.timezone)),n._schedule(n.opts,e)}),s),{stop:function(){n.opts.kill=!0,n.opts.currentTimeout&&clearTimeout(n.opts.currentTimeout)},pause:function(){return(n.opts.paused=!0)&&!n.opts.kill},resume:function(){return!(n.opts.paused=!1)&&!n.opts.kill}}};const i=n;var a=e.P,h=e.Z;export{a as Cron,h as default};
|
package/dist-legacy/croner.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Cron=e():t.Cron=e()}(this,(function(){return(()=>{"use strict";var t={d:(e,
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Cron=e():t.Cron=e()}(this,(function(){return(()=>{"use strict";var t={d:(e,r)=>{for(var s in r)t.o(r,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:r[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{default:()=>i});function r(t,e){if(this.timezone=e,t&&t instanceof Date)this.fromDate(t);else if(void 0===t)this.fromDate(new Date);else if(t&&"string"==typeof t)this.fromString(t);else{if(!(t instanceof r))throw new TypeError("CronDate: Invalid type passed as parameter to CronDate constructor");this.fromCronDate(t)}}function s(t){this.pattern=t,this.seconds=Array(60).fill(0),this.minutes=Array(60).fill(0),this.hours=Array(24).fill(0),this.days=Array(31).fill(0),this.months=Array(12).fill(0),this.daysOfWeek=Array(8).fill(0),this.parse()}r.prototype.fromDate=function(t){let e=t.getTime();this.timezone&&(t=function(t,e){return new Date(t.toLocaleString("en-US",{timeZone:e}))}(t,this.timezone));let r=t.getTime();this.UTCmsOffset=r-e,this.milliseconds=t.getMilliseconds(),this.seconds=t.getSeconds(),this.minutes=t.getMinutes(),this.hours=t.getHours(),this.days=t.getDate(),this.months=t.getMonth(),this.years=t.getFullYear()},r.prototype.fromCronDate=function(t){this.UTCmsOffset=t.UTCmsOffset,this.milliseconds=t.milliseconds,this.seconds=t.seconds,this.minutes=t.minutes,this.hours=t.hours,this.days=t.days,this.months=t.months,this.years=t.years},r.prototype.fromString=function(t){let e=Date.parse(t);if(isNaN(e))throw new TypeError("CronDate: Provided string value for CronDate could not be parsed as date.");this.fromDate(new Date(e))},r.prototype.increment=function(t){this.seconds+=1,this.milliseconds=0;let e=this,r=function(t,r,s,o){for(let n=void 0===o?e[t]+s:0+s;n<r[t].length;n++)if(r[t][n])return e[t]=n-s,!0;return!1},s=[["seconds","minutes",0],["minutes","hours",0],["hours","days",0],["days","months",-1],["months","years",0]],o=0;for(;o<5;){if(!r(s[o][0],t,s[o][2]))for(this[s[o][1]]++;o>=0;)r(s[o][0],t,s[o][2],0),o--;o++}for(;!t.daysOfWeek[this.getDate().getDay()];)this.days+=1;return this},r.prototype.getDate=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,this.milliseconds-this.UTCmsOffset)},r.prototype.getTime=function(){return new Date(this.years,this.months,this.days,this.hours,this.minutes,this.seconds,this.milliseconds-this.UTCmsOffset).getTime()},s.prototype.parse=function(){if("string"!=typeof this.pattern&&this.pattern.constructor!==String)throw new TypeError("CronPattern: Pattern has to be of type string.");let t,e,r,s,o,n=this.pattern.trim().replace(/\s+/g," ").split(" "),i=/[^/*0-9,-]+/;if(n.length<5||n.length>6)throw new TypeError("CronPattern: invalid configuration format ('"+this.pattern+"'), exacly five or six space separated parts required.");for(5===n.length&&n.unshift("0"),e=0;e<n.length;e++)if(t=n[e].trim(),i.test(t))throw new TypeError("CronPattern: configuration entry "+(e+1)+" ("+t+") contains illegal characters.");if(r="*"!==n[4],s="*"!==n[5],o="*"!==n[3],s&&(r||o))throw new TypeError("CronPattern: configuration invalid, you can not combine month/date with day of week.");this.partToArray("seconds",n[0],0),this.partToArray("minutes",n[1],0),this.partToArray("hours",n[2],0),this.partToArray("days",n[3],-1),this.partToArray("months",n[4],-1),this.partToArray("daysOfWeek",n[5],0),this.daysOfWeek[7]&&(this.daysOfWeek[0]=1)},s.prototype.partToArray=function(t,e,r){let s,o,n,i,a,h=this[t];if("*"!==e)if(o=e.split(","),o.length>1)for(s=0;s<o.length;s++)this.partToArray(t,o[s],r);else if(-1!==e.indexOf("-")){if(o=e.split("-"),2!==o.length)throw new TypeError("CronPattern: Syntax error, illegal range: '"+e+"'");if(n=parseInt(o[0],10)+r,i=parseInt(o[1],10)+r,isNaN(n))throw new TypeError("CronPattern: Syntax error, illegal lower range (NaN)");if(isNaN(i))throw new TypeError("CronPattern: Syntax error, illegal upper range (NaN)");if(n<0||i>=h.length)throw new TypeError("CronPattern: Value out of range: '"+e+"'");if(n>i)throw new TypeError("CronPattern: From value is larger than to value: '"+e+"'");for(s=n;s<=i;s++)h[s+r]=1}else if(-1!==e.indexOf("/")){if(o=e.split("/"),2!==o.length)throw new TypeError("CronPattern: Syntax error, illegal stepping: '"+e+"'");if("*"!==o[0])throw new TypeError("CronPattern: Syntax error, left part of / needs to be * : '"+e+"'");if(a=parseInt(o[1],10),isNaN(a))throw new TypeError("CronPattern: Syntax error, illegal stepping: (NaN)");if(0===a)throw new TypeError("CronPattern: Syntax error, illegal stepping: 0");if(a>h.length)throw new TypeError("CronPattern: Syntax error, steps cannot be greater than maximum value of part ("+h.length+")");for(s=0;s<h.length;s+=a)h[s+r]=1}else{if(s=parseInt(e,10)+r,s<0||s>=h.length)throw new TypeError("CronPattern: "+t+" value out of range: '"+e+"'");h[s]=1}else for(s=0;s<h.length;s++)h[s]=1};const o=Math.pow(2,31)-1;function n(t,e,r){let o=this;return this instanceof n?(o.pattern=new s(t),o.schedulerDefaults={maxRuns:1/0,kill:!1},"function"==typeof e&&(r=e,e={}),o.opts=o.validateOpts(e||{}),void 0===r?o:this.schedule(e,r)):new n(t,e,r)}n.prototype.next=function(t){let e=this._next(t);return e?e.getDate():null},n.prototype.previous=function(){return this.opts.previous?this.opts.previous.getDate():null},n.prototype._next=function(t){t=new r(t,this.opts.timezone),this.opts.startAt&&t&&t.getTime()<this.opts.startAt.getTime()&&(t=new r(this.opts.startAt,this.opts.timezone));let e=new r(t,this.opts.timezone).increment(this.pattern);return this.opts.maxRuns<=0||this.opts.kill||this.opts.stopAt&&e.getTime()>=this.opts.stopAt.getTime()?null:e},n.prototype.validateOpts=function(t){return t.startAt&&(t.startAt=new r(t.startAt,t.timezone)),t.stopAt&&(t.stopAt=new r(t.stopAt,t.timezone)),t},n.prototype.msToNext=function(t){t=t||new r(void 0,this.opts.timezone);let e=this._next(t);return e?e.getTime()-t.getTime():null},n.prototype.schedule=function(t,e){e||(e=t,t=this.opts),t.paused=void 0!==t.paused&&t.paused,t.kill=t.kill||this.schedulerDefaults.kill,t.maxRuns||0===t.maxRuns||(t.maxRuns=this.schedulerDefaults.maxRuns),this.opts=this.validateOpts(t||{}),this._schedule(t,e)},n.prototype._schedule=function(t,e){let s,n=this,i=n.maxDelay||o;if(s=this.msToNext(n.opts.previous),null!==s)return s>i&&(s=i),n.opts.currentTimeout=setTimeout((function(){s!==i&&(n.opts.paused||(n.opts.maxRuns--,e()),n.opts.previous=new r(n.opts.previous,n.opts.timezone)),n._schedule(n.opts,e)}),s),{stop:function(){n.opts.kill=!0,n.opts.currentTimeout&&clearTimeout(n.opts.currentTimeout)},pause:function(){return(n.opts.paused=!0)&&!n.opts.kill},resume:function(){return!(n.opts.paused=!1)&&!n.opts.kill}}};const i=n;return e.default})()}));
|