UNPKG

@qntm-code/utils

Version:

A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.

13 lines (12 loc) 493 B
/** * Gets the month names for the provided locale. Defaults to the browser's locale. Optionally, you can provide a format. */ export function getMonthNames(options) { const { locale, format } = { locale: navigator.language, format: 'long', ...options }; const formatter = new Intl.DateTimeFormat(locale, { month: format }); const monthNames = []; for (let i = 0; i < 12; i++) { monthNames.push(formatter.format(new Date(1970, i, 1))); } return monthNames; }