From f69b0ea7b61be400e3dd0209380141bbaffbee4e Mon Sep 17 00:00:00 2001 From: maximelkin Date: Tue, 23 Jan 2018 21:43:37 +0300 Subject: [PATCH] add @types/node-cron (#23062) * add node-cron * Update tslint.json Remove lint rule --- types/node-cron/index.d.ts | 15 ++++++++++ types/node-cron/node-cron-tests.ts | 47 ++++++++++++++++++++++++++++++ types/node-cron/tsconfig.json | 25 ++++++++++++++++ types/node-cron/tslint.json | 3 ++ 4 files changed, 90 insertions(+) create mode 100644 types/node-cron/index.d.ts create mode 100644 types/node-cron/node-cron-tests.ts create mode 100644 types/node-cron/tsconfig.json create mode 100644 types/node-cron/tslint.json diff --git a/types/node-cron/index.d.ts b/types/node-cron/index.d.ts new file mode 100644 index 0000000000..75ddaefdde --- /dev/null +++ b/types/node-cron/index.d.ts @@ -0,0 +1,15 @@ +// Type definitions for node-cron 1.2 +// Project: http://merencia.com/node-cron/ +// Definitions by: morsic +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// immediateStart - default true +export function schedule(a: string, func: () => void, immediateStart?: boolean): ScheduledTask; + +export function validate(a: string): boolean; + +export interface ScheduledTask { + start: () => this; + stop: () => this; + destroy: () => void; +} diff --git a/types/node-cron/node-cron-tests.ts b/types/node-cron/node-cron-tests.ts new file mode 100644 index 0000000000..c670924d27 --- /dev/null +++ b/types/node-cron/node-cron-tests.ts @@ -0,0 +1,47 @@ +/// + +import cron = require('node-cron'); + +// tslint:disable-next-line no-console +const log = console.log; + +cron.schedule('* * * * *', () => { + log('running a task every minute'); +}); + +cron.schedule('1-5 * * * *', () => { + log('running every minute to 1 from 5'); +}); + +// tslint:disable-next-line rule +const task = cron.schedule('* * * * *', () => { + log('immediately started'); + // because of manual call start method +}, false); + +task.start(); + +const task1 = cron.schedule('* * * * *', () => { + log('will execute every minute until stopped'); +}); + +task1.start(); + +const task2 = cron.schedule('* * * * *', () => { + log('will execute every minute until stopped'); +}); + +task2.stop(); + +const task3 = cron.schedule('* * * * *', () => { + log('will execute every minute until stopped'); +}); + +task3.destroy(); + +const valid = cron.validate('59 * * * *'); +const invalid = cron.validate('60 * * * *'); + +if (valid && !invalid) { + log('validator works'); +} diff --git a/types/node-cron/tsconfig.json b/types/node-cron/tsconfig.json new file mode 100644 index 0000000000..e1ec63395b --- /dev/null +++ b/types/node-cron/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "strictNullChecks": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "strictFunctionTypes": true, + "noUnusedParameters": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "node-cron-tests.ts" + ] +} diff --git a/types/node-cron/tslint.json b/types/node-cron/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/node-cron/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}