Skip to content
This repository was archived by the owner on Oct 8, 2023. It is now read-only.

Commit 9325197

Browse files
committed
finish up
1 parent d931310 commit 9325197

File tree

5 files changed

+25
-113
lines changed

5 files changed

+25
-113
lines changed

README.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ npm install --save node-cron
2828
Import node-cron and schedule a task:
2929

3030
```javascript
31-
var cron = require('node-cron');
31+
const cron = require('node-cron');
3232

3333
cron.schedule('* * * * *', () => {
3434
console.log('running a task every minute');
@@ -70,7 +70,7 @@ This is a quick reference to cron syntax and also shows the options supported by
7070
You may use multiples values separated by comma:
7171

7272
```javascript
73-
var cron = require('node-cron');
73+
const cron = require('node-cron');
7474

7575
cron.schedule('1,2,4,5 * * * *', () => {
7676
console.log('running every minute 1, 2, 4 and 5');
@@ -82,7 +82,7 @@ cron.schedule('1,2,4,5 * * * *', () => {
8282
You may also define a range of values:
8383

8484
```javascript
85-
var cron = require('node-cron');
85+
const cron = require('node-cron');
8686

8787
cron.schedule('1-5 * * * *', () => {
8888
console.log('running every minute to 1 from 5');
@@ -94,7 +94,7 @@ cron.schedule('1-5 * * * *', () => {
9494
Step values can be used in conjunction with ranges, following a range with '/' and a number. e.g: `1-10/2` that is the same as `2,4,6,8,10`. Steps are also permitted after an asterisk, so if you want to say “every two minutes”, just use `*/2`.
9595

9696
```javascript
97-
var cron = require('node-cron');
97+
const cron = require('node-cron');
9898

9999
cron.schedule('*/2 * * * *', () => {
100100
console.log('running a task every two minutes');
@@ -106,7 +106,7 @@ cron.schedule('*/2 * * * *', () => {
106106
For month and week day you also may use names or short names. e.g:
107107

108108
```javascript
109-
var cron = require('node-cron');
109+
const cron = require('node-cron');
110110

111111
cron.schedule('* * * January,September Sunday', () => {
112112
console.log('running on Sundays of January and September');
@@ -116,7 +116,7 @@ cron.schedule('* * * January,September Sunday', () => {
116116
Or with short names:
117117

118118
```javascript
119-
var cron = require('node-cron');
119+
const cron = require('node-cron');
120120

121121
cron.schedule('* * * Jan,Sep Sun', () => {
122122
console.log('running on Sundays of January and September');
@@ -143,7 +143,7 @@ Arguments:
143143
**Example**:
144144

145145
```js
146-
var cron = require('node-cron');
146+
const cron = require('node-cron');
147147

148148
cron.schedule('0 1 * * *', () => {
149149
console.log('Running a job at 01:00 at America/Sao_Paulo timezone');
@@ -160,9 +160,9 @@ Arguments:
160160
Starts the scheduled task.
161161

162162
```javascript
163-
var cron = require('node-cron');
163+
const cron = require('node-cron');
164164

165-
var task = cron.schedule('* * * * *', () => {
165+
const task = cron.schedule('* * * * *', () => {
166166
console.log('stopped task');
167167
}, {
168168
scheduled: false
@@ -176,9 +176,9 @@ task.start();
176176
The task won't be executed unless re-started.
177177

178178
```javascript
179-
var cron = require('node-cron');
179+
const cron = require('node-cron');
180180

181-
var task = cron.schedule('* * * * *', () => {
181+
const task = cron.schedule('* * * * *', () => {
182182
console.log('will execute every minute until stopped');
183183
});
184184

@@ -190,10 +190,10 @@ task.stop();
190190
Validate that the given string is a valid cron expression.
191191

192192
```javascript
193-
var cron = require('node-cron');
193+
const cron = require('node-cron');
194194

195-
var valid = cron.validate('59 * * * *');
196-
var invalid = cron.validate('60 * * * *');
195+
const valid = cron.validate('59 * * * *');
196+
const invalid = cron.validate('60 * * * *');
197197
```
198198

199199
## Issues

src/background-scheduled-task/daemon.mjs

-19
This file was deleted.

src/background-scheduled-task/index.mjs

-67
This file was deleted.

src/convert-expression/step-values-conversion.mjs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
export default (() => {
22
function convertSteps(expressions){
3-
var stepValuePattern = /^(.+)\/(\w+)$/;
4-
for(var i = 0; i < expressions.length; i++){
5-
var match = stepValuePattern.exec(expressions[i]);
6-
var isStepValue = match !== null && match.length > 0;
3+
const stepValuePattern = /^(.+)\/(\w+)$/;
4+
for(let i = 0; i < expressions.length; i++){
5+
const match = stepValuePattern.exec(expressions[i]);
6+
const isStepValue = match !== null && match.length > 0;
77
if(isStepValue){
8-
var baseDivider = match[2];
8+
const baseDivider = match[2];
99
if(isNaN(baseDivider)){
1010
throw baseDivider + ' is not a valid step value';
1111
}
12-
var values = match[1].split(',');
13-
var stepValues = [];
14-
var divider = parseInt(baseDivider, 10);
15-
for(var j = 0; j <= values.length; j++){
16-
var value = parseInt(values[j], 10);
12+
const values = match[1].split(',');
13+
let stepValues = [];
14+
const divider = parseInt(baseDivider, 10);
15+
for(let j = 0; j <= values.length; j++){
16+
let value = parseInt(values[j], 10);
1717
if(value % divider === 0){
1818
stepValues.push(value);
1919
}

src/node-cron.mjs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import ScheduledTask from './scheduled-task.mjs'
2-
import BackgroundScheduledTask from './background-scheduled-task/index.mjs'
32
import validation from './pattern-validation.mjs'
43
import storage from './storage.mjs'
54

@@ -28,8 +27,7 @@ import storage from './storage.mjs'
2827
}
2928

3029
function createTask(expression, func, options) {
31-
if (typeof func === 'string')
32-
return new BackgroundScheduledTask(expression, func, options);
30+
if (typeof func !== 'function') throw 'callback function must be a function';
3331

3432
return new ScheduledTask(expression, func, options);
3533
}

0 commit comments

Comments
 (0)