Comparing version 1.1.28 to 1.1.29
{ | ||
"name": "croner", | ||
"version": "1.1.28", | ||
"version": "1.1.29", | ||
"description": "Isomorphic JavaScript cron parser and scheduler.", | ||
@@ -12,12 +12,2 @@ "author": "Hexagon <github.com/hexagon>", | ||
], | ||
"scripts": { | ||
"test": "npm run test:mocha", | ||
"test:mocha": "mocha", | ||
"test:lint": "eslint ./src/croner.js", | ||
"test:lint:fix": "eslint --fix ./src/croner.js", | ||
"build": "npm run test:lint && webpack && npm run test:mocha" | ||
}, | ||
"main": "index.js", | ||
"browser": "./dist/croner.min.js", | ||
"module": "./dist/croner.min.mjs", | ||
"repository": { | ||
@@ -38,2 +28,15 @@ "type": "git", | ||
], | ||
"scripts": { | ||
"test": "npm run test:mocha", | ||
"test:mocha": "mocha", | ||
"test:lint": "eslint ./src/croner.js", | ||
"test:lint:fix": "eslint --fix ./src/croner.js", | ||
"build": "npm run test:lint && npm run build:typings && npm run build:webpack && npm run test:mocha", | ||
"build:webpack": "webpack", | ||
"build:typings": "tsc" | ||
}, | ||
"main": "index.js", | ||
"browser": "./dist/croner.min.js", | ||
"module": "./dist/croner.min.mjs", | ||
"types": "./types/croner.d.ts", | ||
"devDependencies": { | ||
@@ -43,2 +46,3 @@ "eslint": "^7.32.0", | ||
"should": "*", | ||
"typescript": "^4.4.3", | ||
"webpack": "^5.56.1", | ||
@@ -45,0 +49,0 @@ "webpack-cli": "^4.8.0" |
@@ -1,2 +0,1 @@ | ||
# Croner | ||
@@ -9,4 +8,6 @@ | ||
Supports node.js, require.js, es-module and stand alone usage. | ||
Supports Node.js, requirejs, es-module and stand alone usage. | ||
Documented with JSDoc for intellisense, and complete TypeScript typings for type checking. | ||
```html | ||
@@ -13,0 +14,0 @@ <script src="//cdn.56k.guru/js/croner/latest/croner.min.js"></script> |
/* ------------------------------------------------------------------------------------ | ||
Croner 1.1.21 - MIT License - Hexagon <github.com/Hexagon> | ||
Croner 1.1.29 - MIT License - Hexagon <github.com/Hexagon> | ||
@@ -13,3 +13,3 @@ Pure JavaScript Isomorphic cron parser and scheduler without dependencies. | ||
Copyright (c) 2015-2017 Hexagon <github.com/Hexagon> | ||
Copyright (c) 2015-2021 Hexagon <github.com/Hexagon> | ||
@@ -34,2 +34,45 @@ Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// ---- Type definitions ---------------------------------------------------------------- | ||
/** | ||
* @typedef {"seconds" | "minutes" | "hours" | "days" | "months" | "daysOfWeek"} CronPatternPart | ||
*/ | ||
/** | ||
* @typedef {0 | -1} CronIndexOffset | ||
*/ | ||
/** | ||
* @typedef {Date | undefined} CronNextResult | ||
*/ | ||
/** | ||
* @typedef {Object} CronOptions - Cron scheduler options | ||
* @property {boolean} [paused] - Job is paused | ||
* @property {boolean} [kill] - Job is about to be killed | ||
* @property {boolean} [rest] - Internal: Milliseconds left from previous run | ||
* @property {number} [currentTimeout] - Internal: setTimeout "id" | ||
* @property {CronNextResult} [previous] - Previous run time | ||
* @property {string | Date} [startAt] - When to start running | ||
* @property {string | Date} [stopAt] - When to stop running | ||
*/ | ||
/** | ||
* @typedef {Function} CronJobStop - Stop current job | ||
* @returns {boolean} - If pause was successful | ||
*/ | ||
/** | ||
* @typedef {Function} CronJobResume - Resume current job | ||
* @returns {boolean} - If resume was successful | ||
*/ | ||
/** | ||
* @typedef {Object} CronJob - Cron job control functions | ||
* @property {CronJobStop} stop | ||
* @property {CronJobResume} pause | ||
* @property {Function} resume | ||
*/ | ||
// Many JS engines stores the delay as a 32-bit signed integer internally. | ||
@@ -70,2 +113,7 @@ // This causes an integer overflow when using delays larger than 2147483647, | ||
/** | ||
* Converts date to CronDate | ||
* @constructor | ||
* @param {date} date - Input date | ||
*/ | ||
function CronDate (date) { | ||
@@ -81,2 +129,7 @@ this.milliseconds = date.getMilliseconds(); | ||
/** | ||
* Increment to next run time | ||
* | ||
* @param {string} pattern - The pattern used to increment current state | ||
*/ | ||
CronDate.prototype.increment = function (pattern) { | ||
@@ -86,2 +139,14 @@ | ||
/** | ||
* Find next | ||
* | ||
* @param {string} target | ||
* @param {string} pattern | ||
* @param {string} offset | ||
* @param {string} override | ||
* | ||
* @returns {boolean} | ||
* | ||
*/ | ||
findNext = function (target, pattern, offset, override) { | ||
@@ -160,2 +225,8 @@ | ||
/** | ||
* Convert current state back to a javascript Date() | ||
* | ||
* @returns {date} | ||
* | ||
*/ | ||
CronDate.prototype.getDate = function () { | ||
@@ -171,2 +242,7 @@ return new Date(this.years, this.months, this.days, this.hours, this.minutes, this.seconds, 0); | ||
/** | ||
* Create a CronPattern instance from pattern string ('* * * * * *') | ||
* @constructor | ||
* @param {string} pattern - Input pattern | ||
*/ | ||
function CronPattern (pattern) { | ||
@@ -187,2 +263,5 @@ | ||
/** | ||
* Parse current pattern, will raise an error on failure | ||
*/ | ||
CronPattern.prototype.parse = function () { | ||
@@ -244,2 +323,9 @@ | ||
/** | ||
* 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. | ||
* | ||
* @param {CronPatternPart} type - Seconds/minutes etc | ||
* @param {string} conf - Current pattern part - *, 0-1 etc | ||
* @param {CronIndexOffset} valueIndexOffset - 0 or -1. 0 for seconds,minutes, hours as they start on 1. -1 on days and months, as the start on 0 | ||
*/ | ||
CronPattern.prototype.partToArray = function (type, conf, valueIndexOffset) { | ||
@@ -355,3 +441,11 @@ | ||
// | ||
/** | ||
* Cron entrypoint | ||
* | ||
* @constructor | ||
* @param {string} pattern - Input pattern | ||
* @param {CronOptions | Function} [options] - Options | ||
* @param {Function} [fn] - Function to be run each iteration of pattern | ||
* @returns {Cron | CronJob} | ||
*/ | ||
function Cron (pattern, options, fn) { | ||
@@ -365,4 +459,6 @@ let self = this; | ||
/** @type {CronPattern} */ | ||
self.pattern = new CronPattern(pattern); | ||
/** @type {CronOptions} */ | ||
self.schedulerDefaults = { | ||
@@ -381,2 +477,3 @@ stopAt: Infinity, | ||
// Store and validate options | ||
/** @type {CronOptions} */ | ||
self.opts = self.validateOpts(options || {}); | ||
@@ -397,3 +494,8 @@ | ||
// "Exposed" version of next strips milliseconds | ||
/** | ||
* Find next runtime, based on supplied date. Strips milliseconds. | ||
* | ||
* @param {Date} prev - Input pattern | ||
* @returns {CronNextResult} - Next run time | ||
*/ | ||
Cron.prototype.next = function (prev) { | ||
@@ -405,3 +507,8 @@ let dirtyDate = this._next(prev); | ||
// Cron needs millseconds internally, hence _next | ||
/** | ||
* Internal version of next. Cron needs millseconds internally, hence _next. | ||
* | ||
* @param {Date} prev - Input pattern | ||
* @returns {CronNextResult} - Next run time | ||
*/ | ||
Cron.prototype._next = function (prev) { | ||
@@ -436,2 +543,8 @@ | ||
/** | ||
* Validate (and cleans) options. Raises error on failure. | ||
* | ||
* @param {CronOptions} opts - Input options | ||
* @returns {CronOptions} - Clean and validated options. | ||
*/ | ||
Cron.prototype.validateOpts = function (opts) { | ||
@@ -464,2 +577,8 @@ // startAt is set, validate it | ||
/** | ||
* Returns number of milliseconds to next run | ||
* | ||
* @param {CronNextResult} [prev=new Date()] - Starting date, defaults to now | ||
* @returns {number | CronNextResult} | ||
*/ | ||
Cron.prototype.msToNext = function (prev) { | ||
@@ -475,2 +594,10 @@ prev = prev || new Date(); | ||
/** | ||
* Schedule a new job | ||
* | ||
* @constructor | ||
* @param {CronOptions | Function} [options] - Options | ||
* @param {Function} [func] - Function to be run each iteration of pattern | ||
* @returns {CronJob} | ||
*/ | ||
Cron.prototype.schedule = function (opts, func) { | ||
@@ -477,0 +604,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66170
16
1260
263
6