| 1 | /* |
| 2 | * weekstart |
| 3 | * https://github.com/gamtiq/weekstart |
| 4 | */ |
| 5 | |
| 6 | /** |
| 7 | * Library to get first day of week. |
| 8 | * |
| 9 | * Uses data from {@link module:langRegionMap langRegionMap.js} and |
| 10 | * {@link module:regionDayMap regionDayMap.js}. |
| 11 | * |
| 12 | * @module main |
| 13 | */ |
| 14 | |
| 15 | import * as api from './api'; |
| 16 | import langRegionMap from './langRegionMap'; |
| 17 | import regionDayMap from './regionDayMap'; |
| 18 | |
| 19 | /** |
| 20 | * Return first day of week for country/region code. |
| 21 | * |
| 22 | * Based on data from: |
| 23 | * - [https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/territory_information.html](https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/territory_information.html) |
| 24 | * - [https://www.iso.org/iso-3166-country-codes.html](https://www.iso.org/iso-3166-country-codes.html) |
| 25 | * |
| 26 | * @example |
| 27 | * getWeekStartByRegion('PNG'); // 1 |
| 28 | * getWeekStartByRegion('qa'); // 6 |
| 29 | * getWeekStartByRegion(462); // 5 |
| 30 | * |
| 31 | * @param {number | string} regionCode |
| 32 | * ISO 3166 Alpha-2, Alpha-3 or numeric code. |
| 33 | * @return {number} |
| 34 | * Code of first day of week for the given country/region code: |
| 35 | * 0 - Sunday, 1 - Monday, 2 - Tuesday, 3 - Wednesday, 4 - Thursday, 5 - Friday, 6 - Saturday. |
| 36 | * @alias module:main.getWeekStartByRegion |
| 37 | * @see module:api.getWeekStartByRegion |
| 38 | */ |
| 39 | export function getWeekStartByRegion(regionCode) { |
| 40 | return api.getWeekStartByRegion(regionCode, regionDayMap); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Return first day of week for locale identifier. |
| 45 | * |
| 46 | * Based on data from: |
| 47 | * - [https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/territory_language_information.html](https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/territory_language_information.html) |
| 48 | * - [https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/language_territory_information.html](https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/language_territory_information.html) |
| 49 | * - [https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/territory_information.html](https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/territory_information.html) |
| 50 | * - [http://www.unicode.org/reports/tr35/tr35.html#Unicode_Language_and_Locale_Identifiers](http://www.unicode.org/reports/tr35/tr35.html#Unicode_Language_and_Locale_Identifiers) |
| 51 | * |
| 52 | * @example |
| 53 | * getWeekStartByLocale('no'); // 1 |
| 54 | * getWeekStartByLocale('Pa_Guru'); // 0 |
| 55 | * getWeekStartByLocale('fr-DZ'); // 6 |
| 56 | * |
| 57 | * @param {string} locale |
| 58 | * Locale identifier. |
| 59 | * @return {number} |
| 60 | * Code of first day of week for the given locale identifier: |
| 61 | * 0 - Sunday, 1 - Monday, 2 - Tuesday, 3 - Wednesday, 4 - Thursday, 5 - Friday, 6 - Saturday. |
| 62 | * @alias module:main.getWeekStartByLocale |
| 63 | * @see module:api.getWeekStartByLocale |
| 64 | */ |
| 65 | export function getWeekStartByLocale(locale) { |
| 66 | return api.getWeekStartByLocale(locale, langRegionMap, regionDayMap); |
| 67 | } |