UNPKG

node-calendar-js

Version:
102 lines (101 loc) 2.63 kB
export declare const CONSTANT_DAYS_ORDER: number[]; export interface CalendarOptions { year?: number; month?: number; } export interface CalendarDaysData { row: number; day?: number; name?: string; holiday: boolean; } export interface CalendarData { year: number; month: number; totalDays: number; monthName: string; days: CalendarDaysData[]; leapYear: boolean; leapMonth: boolean; } export interface createHTMLOptions { includeStyles?: boolean; } declare class Calendar { year: number; month: number; days: string[]; months: string[]; holidays: number[]; /** * Creates new Calendar * @example ```js * const calendar = new Calendar({ year: 2021, month: 6 }); * console.log(calendar.create()); * ``` */ constructor(options?: CalendarOptions); /** * Sets custom days notation * @param days Days name */ setDays(days: string[]): Calendar; /** * Sets custom months notaiton * @param months Months name */ setMonths(months: string[]): Calendar; /** * Sets holidays * @param data Holidays day array. Example: `[0]` refers to `sunday` whereas `[0, 6]` refers to `saturday` and `sunday`. */ setHolidays(data: number[]): this; /** * Returns total number of days in this month */ get length(): number; /** * If it is a leap year */ get leap(): boolean; /** * Returns current month name */ get monthName(): string; /** * Creates calendar * @example ```js * const data = new Calendar({ year: 2020, month: 0 }); * console.log(data.create()); * ``` */ create(): CalendarData; /** * Creates HTML output * @param options Calendar html output options */ toHTML(options?: createHTMLOptions): string; /** * String representation of the calendar */ toString(): string; toJSON(): CalendarData; /** * Static calendar creator * @param year Creates calendar of full year * @example ```js * const calendar = Calendar.createCalendar(2020); * console.log(calendar.map(m => m.monthName)); * ``` */ static createCalendar(year?: number): CalendarData[]; /** * Internal number validation method * @param data data to validate * @param vtype value data type * @param dataType validation data type */ private _validate; } export { Calendar }; export default Calendar;