cron 2.4.2 → 2.4.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [2.4.3](https://github.com/kelektiv/node-cron/compare/v2.4.2...v2.4.3) (2023-08-26)
2
+
3
+
4
+ ### 🐛 Bug Fixes
5
+
6
+ * fix range parsing when upper limit = 0 ([#687](https://github.com/kelektiv/node-cron/issues/687)) ([d96746f](https://github.com/kelektiv/node-cron/commit/d96746f7b8f357e565d1fad48c9f70d3d646da64))
7
+
8
+
9
+ ### 🚨 Tests
10
+
11
+ * add TS types check ([#690](https://github.com/kelektiv/node-cron/issues/690)) ([f046016](https://github.com/kelektiv/node-cron/commit/f046016dc64438c4a12a4615a919b046d3a846de))
12
+
1
13
  ## [2.4.2](https://github.com/kelektiv/node-cron/compare/v2.4.1...v2.4.2) (2023-08-26)
2
14
 
3
15
 
package/lib/time.js CHANGED
@@ -768,7 +768,7 @@ function CronTime(luxon) {
768
768
  if (allRanges[i].match(RE_RANGE)) {
769
769
  allRanges[i].replace(RE_RANGE, ($0, lower, upper, step) => {
770
770
  lower = parseInt(lower, 10);
771
- upper = parseInt(upper, 10) || undefined;
771
+ upper = upper !== undefined ? parseInt(upper, 10) : undefined;
772
772
 
773
773
  const wasStepDefined = !isNaN(parseInt(step, 10));
774
774
  if (step === '0') {
@@ -776,14 +776,14 @@ function CronTime(luxon) {
776
776
  }
777
777
  step = parseInt(step, 10) || 1;
778
778
 
779
- if (upper && lower > upper) {
779
+ if (upper !== undefined && lower > upper) {
780
780
  throw new Error(`Field (${type}) has an invalid range`);
781
781
  }
782
782
 
783
783
  const outOfRangeError =
784
784
  lower < low ||
785
- (upper && upper > high) ||
786
- (!upper && lower > high);
785
+ (upper !== undefined && upper > high) ||
786
+ (upper === undefined && lower > high);
787
787
 
788
788
  if (outOfRangeError) {
789
789
  throw new Error(`Field value (${value}) is out of range`);
@@ -793,7 +793,7 @@ function CronTime(luxon) {
793
793
  lower = Math.min(Math.max(low, ~~Math.abs(lower)), high);
794
794
 
795
795
  // Positive integer lower than constraints[1]
796
- if (upper) {
796
+ if (upper !== undefined) {
797
797
  upper = Math.min(high, ~~Math.abs(upper));
798
798
  } else {
799
799
  // If step is provided, the default upper range is the highest value
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cron",
3
3
  "description": "Cron jobs for your node",
4
- "version": "2.4.2",
4
+ "version": "2.4.3",
5
5
  "author": "Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/kelektiv/node-cron/issues"
@@ -15,6 +15,7 @@
15
15
  "lint": "eslint {lib,tests}/*.js",
16
16
  "test": "jest --coverage",
17
17
  "test:watch": "jest --watch --coverage",
18
+ "test:types": "tsd",
18
19
  "prepare": "husky install",
19
20
  "release": "semantic-release"
20
21
  },
@@ -46,7 +47,8 @@
46
47
  "jest": "~29.5.x",
47
48
  "prettier": "~2.8.x",
48
49
  "semantic-release": "~21.0.x",
49
- "sinon": "^15.0.x"
50
+ "sinon": "^15.0.x",
51
+ "tsd": "^0.28.1"
50
52
  },
51
53
  "keywords": [
52
54
  "cron",
@@ -0,0 +1,85 @@
1
+ import * as luxon from 'luxon';
2
+ import { expectType } from 'tsd';
3
+ import * as cron from '..';
4
+
5
+ const CronJob = cron.CronJob;
6
+ const CronTime = cron.CronTime;
7
+
8
+ const DateTime = luxon.DateTime;
9
+
10
+ const timeZone = 'America/Los_Angeles';
11
+
12
+ // basic cron usage
13
+ const job = new CronJob(
14
+ '* * * * * *',
15
+ () => {},
16
+ null,
17
+ true
18
+ );
19
+
20
+ // using factory function with parameters object
21
+ expectType<cron.CronJob>(cron.job({
22
+ cronTime: '00 30 11 * * 1-5',
23
+ onTick: () => {},
24
+ start: false,
25
+ timeZone: 'America/Los_Angeles'
26
+ }));
27
+
28
+ // with timezone
29
+ new CronJob(
30
+ '* * * * * *',
31
+ () => {},
32
+ null,
33
+ true,
34
+ timeZone
35
+ );
36
+
37
+ // with onComplete
38
+ new CronJob(
39
+ '00 30 11 * * 1-5',
40
+ () => {},
41
+ () => {},
42
+ true,
43
+ timeZone
44
+ );
45
+
46
+ // with Date
47
+ new CronJob(
48
+ new Date(),
49
+ () => {},
50
+ null,
51
+ true,
52
+ timeZone
53
+ );
54
+
55
+ // with Luxon DateTime
56
+ new CronJob(
57
+ DateTime.local(),
58
+ () => {},
59
+ null,
60
+ true,
61
+ timeZone
62
+ );
63
+
64
+ // with system commands
65
+ new CronJob(
66
+ '00 30 11 * * 1-5',
67
+ 'ls',
68
+ { command: 'ls', args: ['./'] },
69
+ true,
70
+ timeZone
71
+ );
72
+
73
+ // check function return types
74
+ expectType<Date>(job.lastDate());
75
+ expectType<luxon.DateTime>(job.nextDates());
76
+ expectType<luxon.DateTime | luxon.DateTime[]>(job.nextDates(1));
77
+ expectType<boolean | undefined>(job.running);
78
+ job.setTime(new CronTime('00 30 11 * * 1-2'));
79
+ job.start();
80
+ job.stop();
81
+
82
+ // check cronTime format
83
+ new CronTime('* * * * * *');
84
+ new CronTime(new Date());
85
+ new CronTime(DateTime.local());