cron 4.0.0 → 4.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## [4.1.0](https://github.com/kelektiv/node-cron/compare/v4.0.0...v4.1.0) (2025-02-24)
2
+
3
+ ### ✨ Features
4
+
5
+ * add isCronTimeValid function to validate cron expressions ([#959](https://github.com/kelektiv/node-cron/issues/959)) ([cbd8106](https://github.com/kelektiv/node-cron/commit/cbd81063229036859fbb6969d4f628a0e7945e57))
6
+
7
+ ### ♻️ Chores
8
+
9
+ * **action:** update actions/setup-node action to v4.2.0 ([#950](https://github.com/kelektiv/node-cron/issues/950)) ([3a4a701](https://github.com/kelektiv/node-cron/commit/3a4a7015b59c56434b462754728e4ed6483202ef))
10
+ * **action:** update github/codeql-action action to v3.28.9 ([#946](https://github.com/kelektiv/node-cron/issues/946)) ([84ebb32](https://github.com/kelektiv/node-cron/commit/84ebb32e0db478e48e82203099ec0e301021cfc3))
11
+ * **action:** update marocchino/sticky-pull-request-comment action to v2.9.1 ([#947](https://github.com/kelektiv/node-cron/issues/947)) ([7cdcbc2](https://github.com/kelektiv/node-cron/commit/7cdcbc21676fa48f78d58146590e9f59796b56b9))
12
+ * **action:** update step-security/harden-runner action to v2.11.0 ([#948](https://github.com/kelektiv/node-cron/issues/948)) ([b7f9c79](https://github.com/kelektiv/node-cron/commit/b7f9c794f95a95d19a4bfa11d2778dc6a0a21666))
13
+ * **deps:** lock file maintenance ([fa08aa3](https://github.com/kelektiv/node-cron/commit/fa08aa3e0edacdc324381cff33160d49b6db6af0))
14
+ * **deps:** lock file maintenance ([#944](https://github.com/kelektiv/node-cron/issues/944)) ([374ac42](https://github.com/kelektiv/node-cron/commit/374ac429d4ff6f19440d4c18d6e366a69cfea233))
15
+ * **deps:** update dependency [@types](https://github.com/types)/node to v22.13.4 ([#952](https://github.com/kelektiv/node-cron/issues/952)) ([05f1702](https://github.com/kelektiv/node-cron/commit/05f17020fe33ded1839c43132caa0b3dc2770f6e))
16
+ * **deps:** update dependency lint-staged to v15.4.3 ([#953](https://github.com/kelektiv/node-cron/issues/953)) ([b99fc3b](https://github.com/kelektiv/node-cron/commit/b99fc3b82c613b3686930f2055a2b8e10134238b))
17
+ * **deps:** update dependency typescript to v5.7.3 ([#949](https://github.com/kelektiv/node-cron/issues/949)) ([5313b71](https://github.com/kelektiv/node-cron/commit/5313b71e20bcd7a417fce03966cfa5c78062b05a))
18
+ * **deps:** update linters ([#954](https://github.com/kelektiv/node-cron/issues/954)) ([9159759](https://github.com/kelektiv/node-cron/commit/91597592d05770b7e31bbd93eb0b4160da175154))
19
+ * **deps:** update semantic-release related packages ([#951](https://github.com/kelektiv/node-cron/issues/951)) ([92d7ac3](https://github.com/kelektiv/node-cron/commit/92d7ac3f8fa6fcbf37ead72abc3f798fdc05370a))
20
+ * remove bower.json, which is unused ([#955](https://github.com/kelektiv/node-cron/issues/955)) ([8e509f3](https://github.com/kelektiv/node-cron/commit/8e509f3ad7dcd5d250e75a41417830b9b01c2bdb))
21
+
1
22
  ## [4.0.0](https://github.com/kelektiv/node-cron/compare/v3.5.0...v4.0.0) (2025-02-19)
2
23
 
3
24
  ### ⚠ Breaking changes
package/README.md CHANGED
@@ -179,6 +179,18 @@ day of week 0-7 (0 or 7 is Sunday, or use names)
179
179
  console.log(`The job would run in ${timeout}ms`);
180
180
  ```
181
181
 
182
+ - `validateCronExpression`: Validates if a given cron expression is valid (returns an object with `valid` and `error` properties).
183
+
184
+ ```javascript
185
+ import * as cron from 'cron';
186
+
187
+ const validation = cron.validateCronExpression('0 0 * * *');
188
+ console.log(`Is the cron expression valid? ${validation.valid}`);
189
+ if (!validation.valid) {
190
+ console.error(`Validation error: ${validation.error}`);
191
+ }
192
+ ```
193
+
182
194
  ### CronJob Class
183
195
 
184
196
  #### Constructor
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { DateTime } from 'luxon';
2
+ import { CronTime } from './time';
2
3
  export { CronJob } from './job';
3
4
  export { CronTime } from './time';
4
5
  export { CronCallback, CronCommand, CronContext, CronJobParams, CronOnCompleteCallback, CronOnCompleteCommand, Ranges, TimeUnit } from './types/cron.types';
5
6
  export declare const sendAt: (cronTime: string | Date | DateTime) => DateTime;
6
7
  export declare const timeout: (cronTime: string | Date | DateTime) => number;
8
+ export declare const validateCronExpression: typeof CronTime.validateCronExpression;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.timeout = exports.sendAt = exports.CronTime = exports.CronJob = void 0;
3
+ exports.validateCronExpression = exports.timeout = exports.sendAt = exports.CronTime = exports.CronJob = void 0;
4
4
  const time_1 = require("./time");
5
5
  var job_1 = require("./job");
6
6
  Object.defineProperty(exports, "CronJob", { enumerable: true, get: function () { return job_1.CronJob; } });
@@ -10,4 +10,5 @@ const sendAt = (cronTime) => new time_1.CronTime(cronTime).sendAt();
10
10
  exports.sendAt = sendAt;
11
11
  const timeout = (cronTime) => new time_1.CronTime(cronTime).getTimeout();
12
12
  exports.timeout = timeout;
13
+ exports.validateCronExpression = time_1.CronTime.validateCronExpression;
13
14
  //# sourceMappingURL=index.js.map
package/dist/time.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DateTime, Zone } from 'luxon';
2
+ import { CronError } from './errors';
2
3
  import { CronJobParams } from './types/cron.types';
3
4
  export declare class CronTime {
4
5
  source: string | DateTime;
@@ -13,6 +14,10 @@ export declare class CronTime {
13
14
  private dayOfWeek;
14
15
  constructor(source: CronJobParams['cronTime'], timeZone?: CronJobParams['timeZone'], utcOffset?: null);
15
16
  constructor(source: CronJobParams['cronTime'], timeZone?: null, utcOffset?: CronJobParams['utcOffset']);
17
+ static validateCronExpression(cronExpression: string): {
18
+ valid: boolean;
19
+ error?: CronError;
20
+ };
16
21
  private _getWeekDay;
17
22
  sendAt(): DateTime;
18
23
  sendAt(i: number): DateTime[];
package/dist/time.js CHANGED
@@ -36,6 +36,20 @@ class CronTime {
36
36
  this._parse(this.source);
37
37
  }
38
38
  }
39
+ static validateCronExpression(cronExpression) {
40
+ try {
41
+ new CronTime(cronExpression);
42
+ return {
43
+ valid: true
44
+ };
45
+ }
46
+ catch (error) {
47
+ return {
48
+ valid: false,
49
+ error
50
+ };
51
+ }
52
+ }
39
53
  _getWeekDay(date) {
40
54
  return date.weekday === 7 ? 0 : date.weekday;
41
55
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cron",
3
3
  "description": "Cron jobs for your node",
4
- "version": "4.0.0",
4
+ "version": "4.1.0",
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"
@@ -28,8 +28,8 @@
28
28
  "luxon": "~3.5.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@commitlint/cli": "19.6.1",
32
- "@eslint/js": "9.17.0",
31
+ "@commitlint/cli": "19.7.1",
32
+ "@eslint/js": "9.20.0",
33
33
  "@fast-check/jest": "2.0.3",
34
34
  "@insurgent/commitlint-config": "20.0.0",
35
35
  "@insurgent/conventional-changelog-preset": "10.0.0",
@@ -40,21 +40,21 @@
40
40
  "@semantic-release/npm": "12.0.1",
41
41
  "@semantic-release/release-notes-generator": "14.0.3",
42
42
  "@types/jest": "29.5.14",
43
- "@types/node": "22.10.5",
43
+ "@types/node": "22.13.4",
44
44
  "@types/sinon": "17.0.3",
45
45
  "chai": "5.1.2",
46
46
  "eslint": "8.57.1",
47
47
  "eslint-config-prettier": "9.1.0",
48
48
  "eslint-plugin-jest": "27.9.0",
49
- "eslint-plugin-prettier": "5.2.1",
49
+ "eslint-plugin-prettier": "5.2.3",
50
50
  "husky": "9.1.7",
51
51
  "jest": "29.7.0",
52
- "lint-staged": "15.3.0",
53
- "prettier": "3.4.2",
54
- "semantic-release": "24.2.1",
52
+ "lint-staged": "15.4.3",
53
+ "prettier": "3.5.1",
54
+ "semantic-release": "24.2.3",
55
55
  "sinon": "19.0.2",
56
56
  "ts-jest": "29.2.5",
57
- "typescript": "5.7.2",
57
+ "typescript": "5.7.3",
58
58
  "typescript-eslint": "7.18.0"
59
59
  },
60
60
  "keywords": [