add node-cron type definition file

This commit is contained in:
Horiuchi_H 2015-04-17 16:06:20 +09:00
parent 52fa2b9ce3
commit 2be58135d2
2 changed files with 93 additions and 0 deletions

66
cron/cron-tests.ts Normal file
View File

@ -0,0 +1,66 @@
/// <reference path="cron.d.ts" />
import cron = require('cron');
var CronJob = cron.CronJob;
var CronTime = cron.CronTime;
var timeZone = 'America/Los_Angeles';
// Usage (basic cron usage):
new CronJob('* * * * * *', () => {
console.log('You will see this message every second');
}, null, true, 'America/Los_Angeles');
// Another cron example
var job = new CronJob('00 30 11 * * 1-5', () => {
/*
* Runs every weekday (Monday through Friday)
* at 11:30:00 AM. It does not run on Saturday
* or Sunday.
*/
}, () => {
/* This function is executed when the job stops */
},
true, /* Start the job right now */
timeZone /* Time zone of this job. */
);
// Another example with Date
var job = new CronJob(new Date(), () => {
/* runs once at the specified date. */
}, () => {
/* This function is executed when the job stops */
},
true, /* Start the job right now */
timeZone /* Time zone of this job. */
);
// For good measure
var job = new CronJob({
cronTime: '00 30 11 * * 1-5',
onTick: () => {
/*
* Runs every weekday (Monday through Friday)
* at 11:30:00 AM. It does not run on Saturday
* or Sunday.
*/
},
start: false,
timeZone: 'America/Los_Angeles'
});
job.start();
// How to check if a cron pattern is valid:
try {
new CronJob('invalid cron pattern', () => {
console.log('this should not be printed');
})
} catch(ex) {
console.log("cron pattern not valid");
}
// Check cronTime fomat
new CronTime('* * * * * *');
new CronTime(new Date());

27
cron/cron.d.ts vendored Normal file
View File

@ -0,0 +1,27 @@
// Type definitions for cron 1.0.9
// Project: https://www.npmjs.com/package/cron
// Definitions by: Hiroki Horiuchi <https://github.com/horiuchi>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "cron" {
interface CronJobStatic {
new(cronTime: string|Date, onTick: () => void, onComplete?: () => void, start?: boolean, timezone?: string, context?: any): CronJob;
new(options: {
cronTime: string|Date; onTick: () => void; onComplete?: () => void; start?: boolean; timezone?: string; context?: any
}): CronJob;
}
interface CronJob {
start(): void;
stop(): void;
}
export var CronJob: CronJobStatic;
interface CronTimeStatic {
new(time: string|Date): CronTime;
}
interface CronTime {}
export var CronTime: CronTimeStatic;
}