[calendar] Add types for calendar (#40322)

This commit is contained in:
Florian Keller
2019-11-12 13:41:42 -08:00
committed by Pranav Senthilnathan
parent 4148f3afa9
commit 2dbf2e48ba
4 changed files with 62 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
import { Calendar } from 'calendar';
const cal = new Calendar();
cal.monthText(2019, 11);
cal.monthText();
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth();
cal.monthDates(
year,
month,
date => date.getMonth() === month ? date.getDate().toString() : ' ',
week => week.join('</td><td>'),
);
+22
View File
@@ -0,0 +1,22 @@
// Type definitions for calendar 0.1
// Project: https://github.com/ramalho/calendar.js#readme
// Definitions by: Florian Keller <https://github.com/ffflorian>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export type DayFormatter = (day: Date) => Date | string;
export type WeekFormatter = (week: Date[]) => Date[] | string;
export const version: string;
export class Calendar {
/**
* @param firstWeekDay default is `0` (Sunday)
*/
constructor(firstWeekDay?: number);
monthDates(year: number, month: number, dayFormatter?: DayFormatter, weekFormatter?: WeekFormatter): Date[];
monthDays(year: number, month: number): Date[];
monthText(): string;
monthText(year: number, month: number): string;
weekStartDate(date: Date): Date;
}
+23
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",
"calendar-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }