Add declarations for 'cron-converter'. (#42744)

This commit is contained in:
Douglas Antunes 2020-03-02 15:59:45 -03:00 committed by GitHub
parent d56a26c8e3
commit 6516f91593
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 161 additions and 0 deletions

View File

@ -0,0 +1,30 @@
import * as moment from 'moment';
import * as Cron from 'cron-converter';
let cronInstance = new Cron(); // $ExpectedType Cron
// Based on examples of README
const a = cronInstance.fromString('*/10 9-17 1 * *'); // $ExpectedType Cron
a.toString(); // $ExpectedType string
a.toArray(); // $ExpectedType Cron.CronArray
cronInstance.fromArray([[0], [1], [1], [5], [0, 2, 4, 6]]); // $ExpectedType Cron
const c = cronInstance.fromString('*/5 * * * *');
c.schedule(); // $ExpectedType Cron.Seeker
c.schedule(moment([2013, 2, 8, 9, 32])); // $ExpectedType Cron.Seeker
const d = c.schedule(new Date(2013, 2, 8, 9, 32)); // $ExpectedType Cron.Seeker
d.next(); // $ExpectedType moment.Moment
d.prev(); // $ExpectedType moment.Moment
d.reset(); // $ExpectedType void
const cronOptions: Cron.Options = {
outputHashes: true,
outputMonthNames: true,
outputWeekdayNames: true,
timezone: 'Europe/London',
}; // $ExpectedType Cron.Options
cronInstance = new Cron(cronOptions); // $ExpectedType Cron

101
types/cron-converter/index.d.ts vendored Normal file
View File

@ -0,0 +1,101 @@
// Type definitions for cron-converter 1.0
// Project: https://github.com/roccivic/cron-converter#readme
// Definitions by: DouglasAntunes <https://github.com/DouglasAntunes>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import * as moment from 'moment';
export as namespace Cron;
export = Cron;
declare class Cron {
/**
* Creates an instance of Cron.
* Cron objects each represent a cron schedule.
* @param options The options to use.
*/
constructor(options?: Cron.Options);
/**
* Parses a 2-dimensional array of integers as a cron schedule.
* @param cronArr The array to parse.
*/
fromArray(cronArr: Cron.CronArray): Cron;
/**
* Parses a cron string.
* @param str The string to parse.
*/
fromString(str: string): Cron;
/**
* Returns the time the schedule would run next.
* @param now A Date or Moment object.
*/
schedule(now?: Date | moment.Moment): Cron.Seeker;
/**
* Returns the cron schedule as a 2-dimensional array of integers.
*/
toArray(): Cron.CronArray;
/**
* Returns the cron schedule as a string.
*/
toString(): string;
}
declare namespace Cron {
type CronArray = [number[], number[], number[], number[], number[]];
class Seeker {
/**
* Creates an instance of Seeker.
* Seeker objects search for execution times of a cron schedule.
* @param cron A Cron instance.
* @param now A Date or Moment object.
*/
constructor(cron: Cron, now: Date);
/**
* Returns the time the schedule would run next.
*/
next(): moment.Moment;
/**
* Returns the time the schedule would have last run at.
*/
prev(): moment.Moment;
/**
* Resets the iterator.
*/
reset(): void;
}
interface Options {
/**
* Changes the numbers to 3 letter weekday names on the `toString()`.
* Default: `false`.
*/
outputWeekdayNames?: boolean;
/**
* Changes the numbers to 3 letter month names on the `toString()`.
* Default: `false`.
*/
outputMonthNames?: boolean;
/**
* Changes the * to H on the `toString()`.
* Default: `false`.
*/
outputHashes?: boolean;
/**
* Defines a timezone to the cron instance.
* Default: `Local timezone`.
*/
timezone?: string;
}
}

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"moment": ">=2.14.0"
}
}

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"cron-converter-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }