mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add declarations for 'cron-converter'. (#42744)
This commit is contained in:
parent
d56a26c8e3
commit
6516f91593
30
types/cron-converter/cron-converter-tests.ts
Normal file
30
types/cron-converter/cron-converter-tests.ts
Normal 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
101
types/cron-converter/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
6
types/cron-converter/package.json
Normal file
6
types/cron-converter/package.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"moment": ">=2.14.0"
|
||||
}
|
||||
}
|
||||
23
types/cron-converter/tsconfig.json
Normal file
23
types/cron-converter/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/cron-converter/tslint.json
Normal file
1
types/cron-converter/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user