From 2dbf2e48ba732ca2699a8bd4d33d4fde758b99e3 Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Tue, 12 Nov 2019 22:41:42 +0100 Subject: [PATCH] [calendar] Add types for calendar (#40322) --- types/calendar/calendar-tests.ts | 16 ++++++++++++++++ types/calendar/index.d.ts | 22 ++++++++++++++++++++++ types/calendar/tsconfig.json | 23 +++++++++++++++++++++++ types/calendar/tslint.json | 1 + 4 files changed, 62 insertions(+) create mode 100644 types/calendar/calendar-tests.ts create mode 100644 types/calendar/index.d.ts create mode 100644 types/calendar/tsconfig.json create mode 100644 types/calendar/tslint.json diff --git a/types/calendar/calendar-tests.ts b/types/calendar/calendar-tests.ts new file mode 100644 index 0000000000..0b740b0c56 --- /dev/null +++ b/types/calendar/calendar-tests.ts @@ -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(''), +); diff --git a/types/calendar/index.d.ts b/types/calendar/index.d.ts new file mode 100644 index 0000000000..94e3633f75 --- /dev/null +++ b/types/calendar/index.d.ts @@ -0,0 +1,22 @@ +// Type definitions for calendar 0.1 +// Project: https://github.com/ramalho/calendar.js#readme +// Definitions by: Florian Keller +// 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; +} diff --git a/types/calendar/tsconfig.json b/types/calendar/tsconfig.json new file mode 100644 index 0000000000..b85b2ac529 --- /dev/null +++ b/types/calendar/tsconfig.json @@ -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" + ] +} diff --git a/types/calendar/tslint.json b/types/calendar/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/calendar/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }