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
Name | Type | Default Value | Description |
---|
year | string or number | | Calendar Year |
month | number | | Calendar Month (0 - 11) |
firstDayOfTheWeek | "sun" or "mon" | "sun" | First day of the week, "sun" for Sunday and "mon" for Monday |
Returns
Type | Description |
---|
Date[] | Calendar dates |
Example
getDates(2018, 8, 'mon');
2. getDays()
Get all localized day names in a week.
Arguments
Name | Type | Default Value | Description |
---|
locale | string | "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
Type | Description |
---|
string[] | Day names |
Example
getDays('en-US', 'short', 'mon');
3. getMonths()
Get all localized month names in a year.
Arguments
Name | Type | Default Value | Description |
---|
locale | string | "en-US" | Locale code (e.g. "en-US", "id-ID") |
format | "numeric", "2-digit", "long" or "short" | "long" | Month format |
Returns
Type | Description |
---|
string[] | Month names |
Example
getMonths('en-US', 'short');