Comparing version 4.0.63 to 4.0.64
{ | ||
"name": "croner", | ||
"version": "4.0.63", | ||
"version": "4.0.64", | ||
"description": "Trigger functions in javascript using Cron syntax. No deps. All features.", | ||
@@ -67,3 +67,3 @@ "author": "Hexagon <github.com/hexagon>", | ||
"eslint": "^8.1.0", | ||
"rollup": "^2.58.1", | ||
"rollup": "^2.58.3", | ||
"typescript": "^4.4.4", | ||
@@ -70,0 +70,0 @@ "uglify-js": "^3.14.2", |
141
README.md
@@ -1,8 +0,6 @@ | ||
<p align="center"> | ||
<img src="https://cdn.jsdelivr.net/gh/hexagon/croner@master/docs/croner.png" alt="Croner" width="150" height="150"><br> | ||
<img src="https://cdn.jsdelivr.net/gh/hexagon/croner@master/docs/croner.png" alt="Croner" width="150" height="108"><br> | ||
Trigger functions in javascript using Cron syntax.<br><br>Try it live on <a href="https://jsfiddle.net/hexag0n/hoa8kwsb/">jsfiddle</a>.<br> | ||
</p> | ||
# Croner | ||
@@ -13,13 +11,12 @@ | ||
* Trigger functions in javascript using [Cron](https://en.wikipedia.org/wiki/Cron#CRON_expression) syntax. | ||
* Pause, resume or stop execution efter a task is scheduled. | ||
* Trigger functions in JavaScript using [Cron](https://en.wikipedia.org/wiki/Cron#CRON_expression) syntax | ||
* Pause, resume or stop execution efter a task is scheduled | ||
* Find first date of next month, find date of next tuesday, etc. | ||
* Supports Node.js from 4.0 to current. Both require (commonjs) and import (module). | ||
* Supports browser use ([UMD](https://github.com/umdjs/umd) (standalone, requirejs etc.), [ES-module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)) | ||
* **Experimental:** Schedule in other timezones than default. | ||
* Works in Node.js >=4.0 (require and import) | ||
* Works in browsers as standalone, UMD or ES-module. | ||
* **Experimental feature:** Schedule in other timezones than default | ||
* Includes [TypeScript](https://www.typescriptlang.org/) typings | ||
Documented with [JSDoc](https://jsdoc.app/) for intellisense, and include [TypeScript](https://www.typescriptlang.org/) typings. | ||
Quick examples: | ||
Quick demo: | ||
```javascript | ||
@@ -31,13 +28,2 @@ // Run a function at the interval set by a cron expression | ||
// Control execution | ||
// job.pause(); | ||
// job.resume(); | ||
// job.stop(); | ||
// Get info | ||
let next = job.next(); | ||
let previous = job.previous(); | ||
``` | ||
```javascript | ||
// What date is next sunday? | ||
@@ -61,9 +47,6 @@ let nextSunday = Cron('0 0 0 * * 7').next(); | ||
```javascript | ||
// ESM Import | ||
// ESM Import ... | ||
import Cron from "croner"; | ||
// ... or | ||
// CommonJS Require | ||
// ... or CommonJS Require | ||
const Cron = require("croner"); | ||
@@ -76,5 +59,5 @@ ``` | ||
* Download latest [zipball](http://github.com/Hexagon/croner/zipball/master/) | ||
* Download latest [zipball](https://github.com/Hexagon/croner/archive/refs/heads/master.zip) | ||
* Unpack | ||
* 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 | ||
* Grab ```croner.min.js``` (UMD and standalone) or ```croner.min.mjs``` (ES-module) from the [dist/](/dist) folder | ||
@@ -99,55 +82,31 @@ #### CDN | ||
... or a ES-module with [import-map](https://github.com/WICG/import-maps) | ||
```html | ||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"croner": "https://cdn.jsdelivr.net/npm/croner@4/dist/croner.min.mjs" | ||
} | ||
} | ||
</script> | ||
<script type="module"> | ||
import Cron from 'croner'; | ||
// ... see usage section ... | ||
</script> | ||
``` | ||
## Signature | ||
Cron takes three arguments; [pattern](#pattern), [options](#options) (optional) and a scheduled function (optional). | ||
Cron takes three arguments | ||
```javascript | ||
* [pattern](#pattern) | ||
* [options](#options) (optional) | ||
* scheduled function (optional) | ||
var scheduler = Cron( <string pattern> [, { ... } ] [, <function toBeRun> ] ); | ||
``` | ||
Cron return a scheduler, which can be used in a couple of different ways. | ||
```javascript | ||
job.next( [ <date previous> ] ); // Get a Date object with next run time according | ||
// to pattern relative to previous, or now if omitted | ||
var job = Cron("* * * * * *" , /*optional*/ { maxRuns: 1 } , /*optional*/ () => {} ); | ||
job.msToNext( [ <date previous> ] ); // Get milliseconds left to next execution | ||
// If function is omitted in constructor, it can be scheduled later | ||
job.schedule(() => {}); | ||
job.previous(); // Gets a Date object with previous run time, or null | ||
// States | ||
let nextRun = job.next( /*optional*/ previousRun ); // Get a Date object representing next run | ||
let prevRun = job.previous( ); | ||
let msToNext = job.msToNext( /*optional*/ previosRun ); // Milliseconds left to next execution | ||
let isRunning = job.isRunning(); | ||
job.schedule( <fn job> ); // If you didn't pass a function to constructor, you can do it here | ||
// Control scheduled execution | ||
job.pause(); | ||
job.resume(); | ||
job.stop(); | ||
job.pause(); // Pause execution | ||
job.resume(); // Resume execution | ||
job.stop(); // Stop execution | ||
``` | ||
## Options | ||
### Options | ||
Options are optional, and passed as the second parameter of cron. | ||
Example: | ||
```javascript | ||
Cron( '* * * * * *', { maxRuns: 4 } ); | ||
``` | ||
| Key | Default value | Data type | Remarks | | ||
@@ -161,28 +120,16 @@ |--------------|----------------|----------------|---------------------------------------| | ||
## Pattern | ||
### Pattern | ||
Pattern is mandatory, and passed as the first argument of Cron. | ||
Example: | ||
```javascript | ||
Cron( '* * * * * *', () => {} ); | ||
// ┌──────────────── (optional) second (0 - 59) | ||
// │ ┌────────────── minute (0 - 59) | ||
// │ │ ┌──────────── hour (0 - 23) | ||
// │ │ │ ┌────────── day of month (1 - 31) | ||
// │ │ │ │ ┌──────── month (1 - 12, JAN-DEC) | ||
// │ │ │ │ │ ┌────── day of week (0 - 6, SUN-Mon) | ||
// │ │ │ │ │ │ (0 to 6 are Sunday to Saturday; 7 is Sunday, the same as 0) | ||
// │ │ │ │ │ │ | ||
// * * * * * * | ||
``` | ||
Composition: | ||
``` | ||
┌──────────────── (optional) second (0 - 59) | ||
│ ┌────────────── minute (0 - 59) | ||
│ │ ┌──────────── hour (0 - 23) | ||
│ │ │ ┌────────── day of month (1 - 31) | ||
│ │ │ │ ┌──────── month (1 - 12, JAN-DEC) | ||
│ │ │ │ │ ┌────── day of week (0 - 6, SUN-Mon) | ||
│ │ │ │ │ │ (0 to 6 are Sunday to Saturday; 7 is Sunday, the same as 0) | ||
│ │ │ │ │ │ | ||
* * * * * * | ||
``` | ||
Details: | ||
| Field | Required | Allowed values | Allowed special characters | Remarks | | ||
@@ -201,13 +148,5 @@ |--------------|----------|----------------|----------------------------|---------------------------------------| | ||
### Minimal | ||
```javascript | ||
// Run a function each second | ||
Cron('* * * * * *', () => { | ||
console.log('This will run every second'); | ||
}); | ||
``` | ||
### Expressions | ||
```javascript | ||
// Run a function the first five seconds of a minute | ||
// Run a function according to pattern | ||
Cron('0-4 */5 1,2,3 * JAN-MAR SAT', function () { | ||
@@ -214,0 +153,0 @@ console.log('This will run the first five seconds every fifth minute'); |
@@ -56,3 +56,2 @@ /* ------------------------------------------------------------------------------------ | ||
/** | ||
@@ -59,0 +58,0 @@ * Many JS engines stores the delay as a 32-bit signed integer internally. |
@@ -228,3 +228,2 @@ import convertTZ from "./timezone.js"; | ||
* @returns {date} | ||
* | ||
*/ | ||
@@ -239,5 +238,5 @@ CronDate.prototype.getDate = function (internal) { | ||
* @public | ||
* | ||
* @param {boolean} internal - If this is an internal call | ||
* @returns {date} | ||
* | ||
*/ | ||
@@ -250,3 +249,3 @@ CronDate.prototype.getTime = function (internal) { | ||
/** | ||
* parseISOLocal | ||
* Takes a iso 8001 local date time string and creates a Date object | ||
* @private | ||
@@ -253,0 +252,0 @@ * |
@@ -27,3 +27,3 @@ /** | ||
/** | ||
* Parse current pattern, will raise an error on failure | ||
* Parse current pattern, will throw on any type of failure | ||
* @private | ||
@@ -30,0 +30,0 @@ */ |
/** | ||
* Converts a date to a specific time zone | ||
* "Converts" a date to a specific time zone | ||
* | ||
* Note: This is only for specific and controlled usage, | ||
* as the internal UTC time of the resulting object will be off. | ||
* | ||
* Example: | ||
* let normalDate = new Date(); // d is a normal Date instance, with local timezone and correct utc representation | ||
* tzDate = convertTZ(d, 'America/New_York') // d is a tainted Date instance, where getHours() | ||
* (for example) will return local time in new york, but getUTCHours() | ||
* will return something irrelevant. | ||
* | ||
* @param {date} date - Input date | ||
@@ -5,0 +14,0 @@ * @param {string} tzString - Timezone string in Europe/Stockholm format |
@@ -45,3 +45,2 @@ /** | ||
* @returns {date} | ||
* | ||
*/ | ||
@@ -52,5 +51,5 @@ public getDate(internal: boolean): any; | ||
* @public | ||
* | ||
* @param {boolean} internal - If this is an internal call | ||
* @returns {date} | ||
* | ||
*/ | ||
@@ -57,0 +56,0 @@ public getTime(internal: boolean): any; |
export default convertTZ; | ||
/** | ||
* Converts a date to a specific time zone | ||
* "Converts" a date to a specific time zone | ||
* | ||
* Note: This is only for specific and controlled usage, | ||
* as the internal UTC time of the resulting object will be off. | ||
* | ||
* Example: | ||
* let normalDate = new Date(); // d is a normal Date instance, with local timezone and correct utc representation | ||
* tzDate = convertTZ(d, 'America/New_York') // d is a tainted Date instance, where getHours() | ||
* (for example) will return local time in new york, but getUTCHours() | ||
* will return something irrelevant. | ||
* | ||
* @param {date} date - Input date | ||
@@ -6,0 +15,0 @@ * @param {string} tzString - Timezone string in Europe/Stockholm format |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
108129
1696
197