1.0.4 • Published 2 years ago

greg-cal v1.0.4

Weekly downloads
192
License
-
Repository
github
Last release
2 years ago

Greg Cal

A Collection of TypeScript utilities for implementing calendar and datepicker. Zero-dependency and lightweight (only 462B).

Installation

Using yarn:

$ yarn add greg-cal

List of Utilities

1. getDates()

Get an array of calendar dates for a given month and year appended with empty dates to fill the days before the first calendar day.

Arguments

NameTypeDefault ValueDescription
yearstring or numberCalendar Year
monthnumberCalendar Month (0 - 11)
firstDayOfTheWeek"sun" or "mon""sun"First day of the week, "sun" for Sunday and "mon" for Monday

Returns

TypeDescription
Date[]Calendar dates

Example

getDates(2018, 8, 'mon');
// => [ null, null, null, null, null, 2018-08-31T17:00:00.000Z, 2018-09-01T17:00:00.000Z, ... ]

2. getDays()

Get all localized day names in a week.

Arguments

NameTypeDefault ValueDescription
localestring"en-US"Locale code (e.g. "en-US", "id-ID")
format"long" or "short""short"Day format
firstDayOfTheWeek"sun" or "mon""sun"First day of the week, "sun" for Sunday and "mon" for Monday

Returns

TypeDescription
string[]Day names

Example

getDays('en-US', 'short', 'mon');
//=> [ 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ]

3. getMonths()

Get all localized month names in a year.

Arguments

NameTypeDefault ValueDescription
localestring"en-US"Locale code (e.g. "en-US", "id-ID")
format"numeric", "2-digit", "long" or "short""long"Month format

Returns

TypeDescription
string[]Month names

Example

getMonths('en-US', 'short');
//=> [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]