| 1 | # weekstart <a name="start"></a> |
| 2 | |
| 3 | [](http://badge.fury.io/js/weekstart) |
| 4 | |
| 5 | Library to get first day of week. |
| 6 | |
| 7 | ```js |
| 8 | getWeekStartByRegion('MAC'); // 0 |
| 9 | |
| 10 | getWeekStartByLocale('arq'); // 6 |
| 11 | ``` |
| 12 | |
| 13 | The library is based on the following data from Unicode (especially from Common Locale Data Repository) and from ISO: |
| 14 | * [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) |
| 15 | * [https://github.com/unicode-org/cldr-json/blob/main/cldr-json/cldr-core/supplemental/weekData.json](https://github.com/unicode-org/cldr-json/blob/main/cldr-json/cldr-core/supplemental/weekData.json) |
| 16 | * [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) |
| 17 | * [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) |
| 18 | * [https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/scripts_languages_and_territories.html](https://unicode-org.github.io/cldr-staging/charts/latest/supplemental/scripts_languages_and_territories.html) |
| 19 | * [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) |
| 20 | * [https://www.iso.org/iso-3166-country-codes.html](https://www.iso.org/iso-3166-country-codes.html) |
| 21 | |
| 22 | There are 2 variants of the library having identical [API](#api): |
| 23 | * `main` - uses base mapping of language code to country code from [langRegionMap](https://github.com/gamtiq/weekstart/blob/master/src/langRegionMap.js). |
| 24 | * `full` - uses full mapping of language code to country code from [fullLangRegionMap](https://github.com/gamtiq/weekstart/blob/master/src/fullLangRegionMap.js). |
| 25 | |
| 26 | [langRegionMap](https://github.com/gamtiq/weekstart/blob/master/src/langRegionMap.js) contains only main language codes. |
| 27 | It is data subset from [fullLangRegionMap](https://github.com/gamtiq/weekstart/blob/master/src/fullLangRegionMap.js). |
| 28 | |
| 29 | ## Table of contents |
| 30 | |
| 31 | * [Installation](#install) |
| 32 | * [Usage](#usage) |
| 33 | * [Examples](#examples) |
| 34 | * [API](#api) |
| 35 | * [Contributing](#contributing) |
| 36 | * [License](#license) |
| 37 | |
| 38 | ## Installation <a name="install"></a> [↑](#start) |
| 39 | |
| 40 | ### Node |
| 41 | |
| 42 | npm install weekstart |
| 43 | |
| 44 | ### [Bower](http://bower.io) |
| 45 | |
| 46 | bower install weekstart |
| 47 | |
| 48 | ### AMD/UMD, <script> |
| 49 | |
| 50 | Use `dist/main.js` or `dist/min/main.js` (minified version). |
| 51 | Use `dist/full.js` or `dist/min/full.js` (minified version) when you need full locale data. |
| 52 | |
| 53 | ## Usage <a name="usage"></a> [↑](#start) |
| 54 | |
| 55 | ### ECMAScript 6 |
| 56 | |
| 57 | ```js |
| 58 | import {getWeekStartByLocale, getWeekStartByRegion} from 'weekstart'; |
| 59 | ``` |
| 60 | |
| 61 | If you need full data: |
| 62 | |
| 63 | ```js |
| 64 | import {getWeekStartByLocale, getWeekStartByRegion} from 'weekstart/full'; |
| 65 | ``` |
| 66 | |
| 67 | ### Node |
| 68 | |
| 69 | ```js |
| 70 | const getWeekStartByLocale = require('weekstart').getWeekStartByLocale; |
| 71 | const getWeekStartByRegion = require('weekstart').getWeekStartByRegion; |
| 72 | ``` |
| 73 | |
| 74 | If you need full data: |
| 75 | |
| 76 | ```js |
| 77 | const getWeekStartByLocale = require('weekstart/full').getWeekStartByLocale; |
| 78 | const getWeekStartByRegion = require('weekstart/full').getWeekStartByRegion; |
| 79 | ``` |
| 80 | |
| 81 | ### AMD/UMD |
| 82 | |
| 83 | ```js |
| 84 | define(['path/to/dist/main.js'], function(weekstart) { |
| 85 | const getWeekStartByLocale = weekstart.getWeekStartByLocale; |
| 86 | const getWeekStartByRegion = weekstart.getWeekStartByRegion; |
| 87 | }); |
| 88 | ``` |
| 89 | |
| 90 | If you need full data: |
| 91 | |
| 92 | ```js |
| 93 | define(['path/to/dist/full.js'], function(weekstart) { |
| 94 | const getWeekStartByLocale = weekstart.getWeekStartByLocale; |
| 95 | const getWeekStartByRegion = weekstart.getWeekStartByRegion; |
| 96 | }); |
| 97 | ``` |
| 98 | |
| 99 | ### Bower, <script> |
| 100 | |
| 101 | ```html |
| 102 | <!-- Use bower_components/weekstart/dist/main.js and bower_components/weekstart/dist/full.js if the library was installed by Bower --> |
| 103 | <script type="text/javascript" src="path/to/dist/main.js"></script> |
| 104 | <script type="text/javascript"> |
| 105 | // weekstart is available via weekstart field of window object |
| 106 | const getWeekStartByLocale = weekstart.getWeekStartByLocale; |
| 107 | const getWeekStartByRegion = weekstart.getWeekStartByRegion; |
| 108 | </script> |
| 109 | ``` |
| 110 | |
| 111 | If you need full data use `path/to/dist/full.js` instead of `path/to/dist/main.js`. |
| 112 | |
| 113 | ## Examples <a name="examples"></a> [↑](#start) |
| 114 | |
| 115 | ```js |
| 116 | getWeekStartByRegion('dj'); // 6 |
| 117 | getWeekStartByRegion('No'); // 1 |
| 118 | getWeekStartByRegion('CAN'); // 0 |
| 119 | getWeekStartByRegion(462); // 5 |
| 120 | |
| 121 | getWeekStartByLocale('Jam'); // 0 |
| 122 | getWeekStartByLocale('Fa'); // 6 |
| 123 | getWeekStartByLocale('vi'); // 1 |
| 124 | getWeekStartByLocale('es_MX'); // 0 |
| 125 | getWeekStartByLocale('az-Arab-IRN'); // 6 |
| 126 | ``` |
| 127 | |
| 128 | In the following examples results are given for the function from `full.js`. |
| 129 | The same calls for the function from `main.js` will return `1`. |
| 130 | |
| 131 | ```js |
| 132 | getWeekStartByLocale('CCP'); // 0 |
| 133 | getWeekStartByLocale('UZ-arab'); // 6 |
| 134 | ``` |
| 135 | |
| 136 | ## API <a name="api"></a> [↑](#start) |
| 137 | |
| 138 | #### getWeekStartByLocale(locale): number |
| 139 | |
| 140 | Return first day of week for locale identifier: |
| 141 | 0 - Sunday, 1 - Monday, 2 - Tuesday, 3 - Wednesday, 4 - Thursday, 5 - Friday, 6 - Saturday. |
| 142 | |
| 143 | #### getWeekStartByRegion(regionCode): number |
| 144 | |
| 145 | Return first day of week for country/region code: |
| 146 | 0 - Sunday, 1 - Monday, 2 - Tuesday, 3 - Wednesday, 4 - Thursday, 5 - Friday, 6 - Saturday. |
| 147 | |
| 148 | See [`docs`](https://gamtiq.github.io/weekstart/) for details. |
| 149 | |
| 150 | ## Contributing <a name="contributing"></a> [↑](#start) |
| 151 | In lieu of a formal styleguide, take care to maintain the existing coding style. |
| 152 | Add unit tests for any new or changed functionality. |
| 153 | Lint and test your code. |
| 154 | |
| 155 | ## License <a name="license"></a> [↑](#start) |
| 156 | Licensed under the [MIT license](https://github.com/gamtiq/weekstart/blob/master/LICENSE). |