@leyyo/localization 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +417 -0
- package/dist/base/base-localization.handler.d.ts +22 -0
- package/dist/base/base-localization.handler.js +35 -0
- package/dist/base/base-localization.handler.js.map +1 -0
- package/dist/base/index.d.ts +2 -0
- package/dist/base/index.js +19 -0
- package/dist/base/index.js.map +1 -0
- package/dist/base/index.types.d.ts +57 -0
- package/dist/base/index.types.js +3 -0
- package/dist/base/index.types.js.map +1 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +19 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/index.types.d.ts +22 -0
- package/dist/config/index.types.js +3 -0
- package/dist/config/index.types.js.map +1 -0
- package/dist/config/localization.config.d.ts +2 -0
- package/dist/config/localization.config.js +27 -0
- package/dist/config/localization.config.js.map +1 -0
- package/dist/country/country-code.d.ts +10 -0
- package/dist/country/country-code.js +19 -0
- package/dist/country/country-code.js.map +1 -0
- package/dist/country/country.handler.d.ts +2 -0
- package/dist/country/country.handler.js +51 -0
- package/dist/country/country.handler.js.map +1 -0
- package/dist/country/country.map.d.ts +3 -0
- package/dist/country/country.map.js +257 -0
- package/dist/country/country.map.js.map +1 -0
- package/dist/country/index.d.ts +3 -0
- package/dist/country/index.js +20 -0
- package/dist/country/index.js.map +1 -0
- package/dist/country/index.types.d.ts +66 -0
- package/dist/country/index.types.js +3 -0
- package/dist/country/index.types.js.map +1 -0
- package/dist/exchange/exchange-code.d.ts +10 -0
- package/dist/exchange/exchange-code.js +23 -0
- package/dist/exchange/exchange-code.js.map +1 -0
- package/dist/exchange/exchange.handler.d.ts +2 -0
- package/dist/exchange/exchange.handler.js +55 -0
- package/dist/exchange/exchange.handler.js.map +1 -0
- package/dist/exchange/exchange.map.d.ts +3 -0
- package/dist/exchange/exchange.map.js +172 -0
- package/dist/exchange/exchange.map.js.map +1 -0
- package/dist/exchange/index.d.ts +3 -0
- package/dist/exchange/index.js +20 -0
- package/dist/exchange/index.js.map +1 -0
- package/dist/exchange/index.types.d.ts +85 -0
- package/dist/exchange/index.types.js +3 -0
- package/dist/exchange/index.types.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +6 -0
- package/dist/internal.js.map +1 -0
- package/dist/language/index.d.ts +3 -0
- package/dist/language/index.js +20 -0
- package/dist/language/index.js.map +1 -0
- package/dist/language/index.types.d.ts +17 -0
- package/dist/language/index.types.js +3 -0
- package/dist/language/index.types.js.map +1 -0
- package/dist/language/language-code.d.ts +7 -0
- package/dist/language/language-code.js +33 -0
- package/dist/language/language-code.js.map +1 -0
- package/dist/language/language.handler.d.ts +12 -0
- package/dist/language/language.handler.js +32 -0
- package/dist/language/language.handler.js.map +1 -0
- package/dist/language/language.map.d.ts +3 -0
- package/dist/language/language.map.js +190 -0
- package/dist/language/language.map.js.map +1 -0
- package/dist/locale/index.d.ts +3 -0
- package/dist/locale/index.js +20 -0
- package/dist/locale/index.js.map +1 -0
- package/dist/locale/index.types.d.ts +60 -0
- package/dist/locale/index.types.js +3 -0
- package/dist/locale/index.types.js.map +1 -0
- package/dist/locale/locale-code.d.ts +9 -0
- package/dist/locale/locale-code.js +25 -0
- package/dist/locale/locale-code.js.map +1 -0
- package/dist/locale/locale.handler.d.ts +18 -0
- package/dist/locale/locale.handler.js +44 -0
- package/dist/locale/locale.handler.js.map +1 -0
- package/dist/locale/locale.map.d.ts +3 -0
- package/dist/locale/locale.map.js +202 -0
- package/dist/locale/locale.map.js.map +1 -0
- package/dist/parser/index.d.ts +2 -0
- package/dist/parser/index.js +19 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/index.types.d.ts +179 -0
- package/dist/parser/index.types.js +3 -0
- package/dist/parser/index.types.js.map +1 -0
- package/dist/parser/localization.parser.d.ts +2 -0
- package/dist/parser/localization.parser.js +363 -0
- package/dist/parser/localization.parser.js.map +1 -0
- package/dist/timezone/index.d.ts +3 -0
- package/dist/timezone/index.js +20 -0
- package/dist/timezone/index.js.map +1 -0
- package/dist/timezone/index.types.d.ts +137 -0
- package/dist/timezone/index.types.js +3 -0
- package/dist/timezone/index.types.js.map +1 -0
- package/dist/timezone/timezone-code.d.ts +9 -0
- package/dist/timezone/timezone-code.js +109 -0
- package/dist/timezone/timezone-code.js.map +1 -0
- package/dist/timezone/timezone.handler.d.ts +2 -0
- package/dist/timezone/timezone.handler.js +94 -0
- package/dist/timezone/timezone.handler.js.map +1 -0
- package/dist/timezone/timezone.map.d.ts +3 -0
- package/dist/timezone/timezone.map.js +608 -0
- package/dist/timezone/timezone.map.js.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Mustafa Yelmer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
# Leyyo: Localization Common
|
|
2
|
+
Common library for Leyyo framework
|
|
3
|
+
|
|
4
|
+
## Import
|
|
5
|
+
- `npm i @leyyo/localization-common`
|
|
6
|
+
|
|
7
|
+
## Usage (Runtime)
|
|
8
|
+
|
|
9
|
+
### Country Code
|
|
10
|
+
> All country codes with alpha 3 and related language codes
|
|
11
|
+
>
|
|
12
|
+
> @see [ISO 3166](https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes)
|
|
13
|
+
>
|
|
14
|
+
```typescript
|
|
15
|
+
import {countryHandler} from "@leyyo/localization-common";
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Country exists
|
|
19
|
+
*/
|
|
20
|
+
console.log(countryHandler.has('IE'));
|
|
21
|
+
// ==> true
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* Get country object as
|
|
25
|
+
* {code: string, name: string, alpha: string, languages: string[]}
|
|
26
|
+
*/
|
|
27
|
+
console.log(countryHandler.get('IE'));
|
|
28
|
+
// ==> {code: 'IE', name: 'Ireland', alpha3: 'IRL', languages: ['en', 'ga']}
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
* Get name of country
|
|
32
|
+
*/
|
|
33
|
+
console.log(countryHandler.getName('IE'));
|
|
34
|
+
// ==> 'Ireland'
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* Get alpha 3 code of country
|
|
38
|
+
*/
|
|
39
|
+
console.log(countryHandler.getAlpha3('IE'));
|
|
40
|
+
// ==> 'IRL'
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
* Get used languages of country
|
|
44
|
+
*/
|
|
45
|
+
console.log(countryHandler.getLanguages('IE'));
|
|
46
|
+
// ==> ['en', 'ga']
|
|
47
|
+
|
|
48
|
+
/*
|
|
49
|
+
* Find all countries by given used language codes
|
|
50
|
+
*/
|
|
51
|
+
console.log(countryHandler.findByLanguage('ga'));
|
|
52
|
+
// ==> ['IE', ...]
|
|
53
|
+
|
|
54
|
+
/*
|
|
55
|
+
* Get country objects by given country codes
|
|
56
|
+
*/
|
|
57
|
+
console.log(countryHandler.getSelected('IE', 'KE'));
|
|
58
|
+
// ==> [
|
|
59
|
+
// {code: 'IE', name: 'Ireland', alpha3: 'IRL', languages: ['en', 'ga']},
|
|
60
|
+
// {code: 'KE', name: 'Kenya', alpha3: 'KEN', languages: ['sw', 'en']}
|
|
61
|
+
// ]
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* List all country objects
|
|
65
|
+
*
|
|
66
|
+
* @note it can be used during combo
|
|
67
|
+
*/
|
|
68
|
+
console.log(countryHandler.getAll()); // A-Z ordered
|
|
69
|
+
// ==> [{code: 'AD', name: 'Andorra', alpha3: 'AND', languages: ['ca']}, ...]
|
|
70
|
+
|
|
71
|
+
/*
|
|
72
|
+
* List all country codes
|
|
73
|
+
*
|
|
74
|
+
* @note it can be used during validations
|
|
75
|
+
*/
|
|
76
|
+
console.log(countryHandler.codes); // A-Z ordered
|
|
77
|
+
// ==> ['AD', 'AE', 'AF', 'AG', 'AI', 'AL', ...]
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Exchange Code
|
|
82
|
+
> All exchange codes with symbol, number and related country codes
|
|
83
|
+
>
|
|
84
|
+
> @see [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217)
|
|
85
|
+
>
|
|
86
|
+
```typescript
|
|
87
|
+
import {exchangeHandler} from "@leyyo/localization-common";
|
|
88
|
+
|
|
89
|
+
/*
|
|
90
|
+
* Exchange exists
|
|
91
|
+
*/
|
|
92
|
+
console.log(exchangeHandler.has('USD'));
|
|
93
|
+
// ==> true
|
|
94
|
+
|
|
95
|
+
/*
|
|
96
|
+
* Get exchange object as
|
|
97
|
+
* {code: string, name: string, symbol: string, number: number, countries: string[]}
|
|
98
|
+
*/
|
|
99
|
+
console.log(exchangeHandler.get('USD'));
|
|
100
|
+
// ==> {code: 'USD', name: 'US Dollar', symbol: '$', number: 840, countries: ['AS', 'GU', 'IO', 'US', 'VG', ...]}
|
|
101
|
+
|
|
102
|
+
/*
|
|
103
|
+
* Get name of exchange
|
|
104
|
+
*/
|
|
105
|
+
console.log(exchangeHandler.getName('USD'));
|
|
106
|
+
// ==> 'US Dollar'
|
|
107
|
+
|
|
108
|
+
/*
|
|
109
|
+
* Get symbol of exchange
|
|
110
|
+
*/
|
|
111
|
+
console.log(exchangeHandler.getSymbol('USD'));
|
|
112
|
+
// ==> '$'
|
|
113
|
+
|
|
114
|
+
/*
|
|
115
|
+
* Get number of exchange
|
|
116
|
+
*/
|
|
117
|
+
console.log(exchangeHandler.getNumber('USD'));
|
|
118
|
+
// ==> 840
|
|
119
|
+
|
|
120
|
+
/*
|
|
121
|
+
* Get related countries of exchange
|
|
122
|
+
*/
|
|
123
|
+
console.log(exchangeHandler.getCountries('USD'));
|
|
124
|
+
// ==> ['AS', 'GU', 'IO', 'US', 'VG', ...]
|
|
125
|
+
|
|
126
|
+
/*
|
|
127
|
+
* Find all exchanges by given country code
|
|
128
|
+
*/
|
|
129
|
+
console.log(exchangeHandler.findByCountry('US'));
|
|
130
|
+
// ==> ['USD', ...]
|
|
131
|
+
|
|
132
|
+
/*
|
|
133
|
+
* Get exchange objects by given codes
|
|
134
|
+
*/
|
|
135
|
+
console.log(exchangeHandler.getSelected('USD', 'EUR'));
|
|
136
|
+
// ==> [
|
|
137
|
+
// {code: 'USD', name: 'US Dollar', symbol: '$', number: 840, countries: ['AS', 'GU', 'IO', 'US', 'VG', ...]},
|
|
138
|
+
// {code: 'EUR', name: 'Euro', symbol: '€', number: 978, countries: ["GB", "AD", "AT", "BE", "CY", ...]}
|
|
139
|
+
// ]
|
|
140
|
+
|
|
141
|
+
/*
|
|
142
|
+
* List all exchange objects
|
|
143
|
+
*
|
|
144
|
+
* @note it can be used during combo
|
|
145
|
+
*/
|
|
146
|
+
console.log(exchangeHandler.getAll()); // A-Z ordered
|
|
147
|
+
// ==> [{code: 'AED', name: 'UAE Dirham', symbol: 'د.إ', number: 784, countries: ['AE']}, ...]
|
|
148
|
+
|
|
149
|
+
/*
|
|
150
|
+
* List all country codes
|
|
151
|
+
*
|
|
152
|
+
* @note it can be used during validations
|
|
153
|
+
*/
|
|
154
|
+
console.log(exchangeHandler.codes); // A-Z ordered
|
|
155
|
+
// ==> ['AED', 'AFN', 'ALL', 'AMD', 'AOA', 'ARS', 'AWG', ...]
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Language Code
|
|
160
|
+
> All language codes
|
|
161
|
+
>
|
|
162
|
+
> @see [ISO 639](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes)
|
|
163
|
+
>
|
|
164
|
+
```typescript
|
|
165
|
+
import {languageHandler} from "@leyyo/localization-common";
|
|
166
|
+
|
|
167
|
+
/*
|
|
168
|
+
* Language exists
|
|
169
|
+
*/
|
|
170
|
+
console.log(languageHandler.has('tr'));
|
|
171
|
+
// ==> true
|
|
172
|
+
|
|
173
|
+
/*
|
|
174
|
+
* Get language object as {code: string, name: string}
|
|
175
|
+
*/
|
|
176
|
+
console.log(languageHandler.get('tr'));
|
|
177
|
+
// ==> {code: 'tr', name: 'Turkish'}
|
|
178
|
+
|
|
179
|
+
/*
|
|
180
|
+
* Get name of language
|
|
181
|
+
*/
|
|
182
|
+
console.log(languageHandler.getName('tr'));
|
|
183
|
+
// ==> 'Turkish'
|
|
184
|
+
|
|
185
|
+
/*
|
|
186
|
+
* Get language objects by given codes
|
|
187
|
+
*/
|
|
188
|
+
console.log(languageHandler.getSelected('tr', 'bg'));
|
|
189
|
+
// ==> [
|
|
190
|
+
// {code: 'tr', name: 'Turkish'},
|
|
191
|
+
// {code: 'bg', name: 'Bulgarian'}
|
|
192
|
+
// ]
|
|
193
|
+
|
|
194
|
+
/*
|
|
195
|
+
* List all language objects
|
|
196
|
+
*
|
|
197
|
+
* @note it can be used during combo
|
|
198
|
+
*/
|
|
199
|
+
console.log(languageHandler.getAll()); // A-Z ordered
|
|
200
|
+
// ==> [{code: 'aa', name: 'Afar'}, ...]
|
|
201
|
+
|
|
202
|
+
/*
|
|
203
|
+
* List all language codes
|
|
204
|
+
*
|
|
205
|
+
* @note it can be used during validations
|
|
206
|
+
*/
|
|
207
|
+
console.log(languageHandler.codes); // A-Z ordered
|
|
208
|
+
// ==> ['aa', 'ab', 'ae', 'af', 'ak', 'am', 'an', 'ar', 'as', 'av', 'ay', 'az', ...]
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Locale Code
|
|
213
|
+
> All locale codes
|
|
214
|
+
>
|
|
215
|
+
> @see [IANA](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry)
|
|
216
|
+
>
|
|
217
|
+
> **Note**
|
|
218
|
+
> It also covers language codes
|
|
219
|
+
>
|
|
220
|
+
```typescript
|
|
221
|
+
import {localeHandler} from "@leyyo/localization-common";
|
|
222
|
+
|
|
223
|
+
/*
|
|
224
|
+
* Locale exists
|
|
225
|
+
*/
|
|
226
|
+
console.log(localeHandler.has('es-ve'));
|
|
227
|
+
// ==> true
|
|
228
|
+
|
|
229
|
+
/*
|
|
230
|
+
* Get locale object as
|
|
231
|
+
* {code: string, name: string, language?: string, countries: string[]}
|
|
232
|
+
*/
|
|
233
|
+
console.log(localeHandler.get('es-ve'));
|
|
234
|
+
// ==> {code: 'es-ve', name: 'Spanish (Venezuela)', language: 'es', countries: ['VE']}
|
|
235
|
+
|
|
236
|
+
/*
|
|
237
|
+
* Get name of locale
|
|
238
|
+
*/
|
|
239
|
+
console.log(localeHandler.getName('es-ve'));
|
|
240
|
+
// ==> 'Spanish (Venezuela)'
|
|
241
|
+
|
|
242
|
+
/*
|
|
243
|
+
* Get language of locale
|
|
244
|
+
*/
|
|
245
|
+
console.log(localeHandler.getLanguage('es-ve'));
|
|
246
|
+
// ==> 'es'
|
|
247
|
+
|
|
248
|
+
/*
|
|
249
|
+
* Get countries of locale
|
|
250
|
+
*/
|
|
251
|
+
console.log(localeHandler.getCountries('es-ve'));
|
|
252
|
+
// ==> ['VE']
|
|
253
|
+
|
|
254
|
+
/*
|
|
255
|
+
* Get locale objects by given codes
|
|
256
|
+
*/
|
|
257
|
+
console.log(localeHandler.getSelected('es-ve', 'fr-mc'));
|
|
258
|
+
// ==> [
|
|
259
|
+
// {code: 'es-ve', name: 'Spanish (Venezuela)', language: 'es', countries: ['VE']},
|
|
260
|
+
// {code: 'fr-mc', name: 'French (Monaco)', language: 'fr', countries: ['MC']}
|
|
261
|
+
// ]
|
|
262
|
+
|
|
263
|
+
/*
|
|
264
|
+
* List all locale objects
|
|
265
|
+
*
|
|
266
|
+
* @note it can be used during combo
|
|
267
|
+
*/
|
|
268
|
+
console.log(localeHandler.getAll()); // A-Z ordered
|
|
269
|
+
// ==> [{code: 'af', name: 'Afrikaans', language: 'af', countries: ['ZA']}, ...]
|
|
270
|
+
|
|
271
|
+
/*
|
|
272
|
+
* List all locale codes
|
|
273
|
+
*
|
|
274
|
+
* @note it can be used during validations
|
|
275
|
+
*/
|
|
276
|
+
console.log(localeHandler.codes); // A-Z ordered
|
|
277
|
+
// ==> ['af', 'sq', 'an', 'ar', 'ar-dz', 'ar-bh', 'ar-eg', ...]
|
|
278
|
+
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Timezone Code
|
|
282
|
+
> All timezone codes
|
|
283
|
+
>
|
|
284
|
+
> @see [TZ](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
|
|
285
|
+
>
|
|
286
|
+
> **Note**
|
|
287
|
+
> It also covers alias timezones
|
|
288
|
+
>
|
|
289
|
+
```typescript
|
|
290
|
+
import {timezoneHandler} from "@leyyo/localization-common";
|
|
291
|
+
|
|
292
|
+
/*
|
|
293
|
+
* Timezone exists
|
|
294
|
+
*/
|
|
295
|
+
console.log(timezoneHandler.has('Africa/Dakar'));
|
|
296
|
+
// ==> true
|
|
297
|
+
|
|
298
|
+
/*
|
|
299
|
+
* Get timezone object as
|
|
300
|
+
* {code: string, name: string, sdt: number, dst: number, parent?: string, countries: string[]}
|
|
301
|
+
*/
|
|
302
|
+
console.log(timezoneHandler.get('Europe/Berlin'));
|
|
303
|
+
// ==> {code: 'Europe/Berlin', name: 'Europe > Berlin', sdt: 1, dst: 2, parent: undefined, countries: ['DE']}
|
|
304
|
+
|
|
305
|
+
/*
|
|
306
|
+
* Get timezone object for alias
|
|
307
|
+
*/
|
|
308
|
+
console.log(timezoneHandler.get('Africa/Dakar')); // it's alias, so points to "Africa/Abidjan"
|
|
309
|
+
// ==> {code: 'Africa/Dakar', name: 'Africa > Abidjan', sdt: 1, dst: 2, parent: 'Africa/Abidjan', countries: ['CI', 'BF', 'GH', 'GM', 'GN', 'IS',...]}
|
|
310
|
+
|
|
311
|
+
/*
|
|
312
|
+
* Get name of timezone
|
|
313
|
+
*/
|
|
314
|
+
console.log(timezoneHandler.getName('Europe/Berlin'));
|
|
315
|
+
// ==> 'Europe > Berlin'
|
|
316
|
+
|
|
317
|
+
/*
|
|
318
|
+
* Get hour for timezone as SDT (3 options)
|
|
319
|
+
*/
|
|
320
|
+
console.log(timezoneHandler.getHour('Europe/Berlin'));
|
|
321
|
+
// ==> 1
|
|
322
|
+
|
|
323
|
+
console.log(timezoneHandler.getSdt('Europe/Berlin'));
|
|
324
|
+
// ==> 1
|
|
325
|
+
|
|
326
|
+
console.log(timezoneHandler.getStandard('Europe/Berlin'));
|
|
327
|
+
// ==> 1
|
|
328
|
+
|
|
329
|
+
/*
|
|
330
|
+
* Get hour for timezone as DST (3 options)
|
|
331
|
+
*/
|
|
332
|
+
console.log(timezoneHandler.getHour('Europe/Berlin', true));
|
|
333
|
+
// ==> 2
|
|
334
|
+
|
|
335
|
+
console.log(timezoneHandler.getDst('Europe/Berlin'));
|
|
336
|
+
// ==> 2
|
|
337
|
+
|
|
338
|
+
console.log(timezoneHandler.getDaylightSaving('Europe/Berlin'));
|
|
339
|
+
// ==> 2
|
|
340
|
+
|
|
341
|
+
/*
|
|
342
|
+
* Get countries of timezone
|
|
343
|
+
*/
|
|
344
|
+
console.log(timezoneHandler.getCountries('Europe/Berlin'));
|
|
345
|
+
// ==> ['DE']
|
|
346
|
+
|
|
347
|
+
/*
|
|
348
|
+
* Get alias status of timezone
|
|
349
|
+
*/
|
|
350
|
+
console.log(timezoneHandler.isAlias('Africa/Dakar'));
|
|
351
|
+
// ==> true
|
|
352
|
+
|
|
353
|
+
console.log(timezoneHandler.isAlias('Africa/Abidjan'));
|
|
354
|
+
// ==> false
|
|
355
|
+
|
|
356
|
+
/*
|
|
357
|
+
* Get timezone objects by given codes
|
|
358
|
+
*/
|
|
359
|
+
console.log(timezoneHandler.getSelected('Europe/Berlin', 'Africa/Dakar'));
|
|
360
|
+
// ==> [
|
|
361
|
+
// {code: 'Europe/Berlin', name: 'Europe > Berlin', sdt: 1, dst: 2, parent: undefined, countries: ['DE']},
|
|
362
|
+
// {code: 'Africa/Dakar', name: 'Africa > Abidjan', sdt: 1, dst: 2, parent: 'Africa/Abidjan', countries: ['CI', 'BF', 'GH', 'GM', 'GN', 'IS',...]}
|
|
363
|
+
// ]
|
|
364
|
+
|
|
365
|
+
/*
|
|
366
|
+
* List all timezone objects
|
|
367
|
+
*
|
|
368
|
+
* @note it can be used during combo
|
|
369
|
+
*/
|
|
370
|
+
console.log(timezoneHandler.getAll()); // A-Z ordered
|
|
371
|
+
// ==> [{code: 'Etc/GMT+1', name: 'Etc > GMT +1', sdt: -1, dst: -1, parent: undefined, countries: []}, ...]
|
|
372
|
+
|
|
373
|
+
/*
|
|
374
|
+
* List all timezone codes
|
|
375
|
+
*
|
|
376
|
+
* @note it can be used during validations
|
|
377
|
+
*/
|
|
378
|
+
console.log(timezoneHandler.codes); // A-Z ordered
|
|
379
|
+
// ==> ['Etc/GMT+1', 'Etc/GMT+2', ...]
|
|
380
|
+
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
## Usage (Design time)
|
|
384
|
+
```typescript
|
|
385
|
+
import type {CountryCode, ExchangeCode, LanguageCode, LocaleCode, TimezoneCode} from "@leyyo/localization-common";
|
|
386
|
+
// please "type" keyword to prevent runtime loading
|
|
387
|
+
|
|
388
|
+
interface MyInterface {
|
|
389
|
+
country: CountryCode;
|
|
390
|
+
exchange: ExchangeCode;
|
|
391
|
+
language: LanguageCode;
|
|
392
|
+
locale: LocaleCode;
|
|
393
|
+
timezone: TimezoneCode;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
## Standards
|
|
400
|
+
- Language: `TS`
|
|
401
|
+
- Eslint: `Yes`
|
|
402
|
+
- Static Code Analysis: `Yes` *IntelliJ Code Inspections*
|
|
403
|
+
- DDD - Document Driven: `Yes`
|
|
404
|
+
- DDD - Domain Driven: `Yes`
|
|
405
|
+
- EDD - Exception Driven: `Yes`
|
|
406
|
+
- TDD - Test Driven: `Yes`
|
|
407
|
+
- LDD - Log Driven: `Yes`
|
|
408
|
+
- 12FA - 12 Factor-App: `50%` *Partially*
|
|
409
|
+
|
|
410
|
+
## Dependencies
|
|
411
|
+
### NO
|
|
412
|
+
|
|
413
|
+
---
|
|
414
|
+
### Prepared by
|
|
415
|
+
- Mustafa Yelmer
|
|
416
|
+
- mustafayelmer(at)gmail.com
|
|
417
|
+
- `2022-07-08`
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BaseLocalizationHandlerLike, BaseLocalizationHandlerRaw, BaseLocalizationHandlerView } from "./index.types";
|
|
2
|
+
/** @inheritDoc */
|
|
3
|
+
export declare abstract class BaseLocalizationHandler<E extends string, W extends BaseLocalizationHandlerView<E>, R extends BaseLocalizationHandlerRaw> implements BaseLocalizationHandlerLike<E, W, R> {
|
|
4
|
+
/**
|
|
5
|
+
* Raw records which is loaded from corresponding map file
|
|
6
|
+
* */
|
|
7
|
+
protected _raw: Record<E, R>;
|
|
8
|
+
/** @inheritDoc */
|
|
9
|
+
readonly codes: ReadonlyArray<E>;
|
|
10
|
+
/** @inheritDoc */
|
|
11
|
+
has(code: E): boolean;
|
|
12
|
+
/** @inheritDoc */
|
|
13
|
+
getRaw(code: E): R;
|
|
14
|
+
/** @inheritDoc */
|
|
15
|
+
getName(code: E): string;
|
|
16
|
+
/** @inheritDoc */
|
|
17
|
+
getAll(): Array<W>;
|
|
18
|
+
/** @inheritDoc */
|
|
19
|
+
abstract get(code: E): W;
|
|
20
|
+
/** @inheritDoc */
|
|
21
|
+
getSelected(...codes: Array<E>): Array<W>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseLocalizationHandler = void 0;
|
|
4
|
+
/** @inheritDoc */
|
|
5
|
+
class BaseLocalizationHandler {
|
|
6
|
+
/** @inheritDoc */
|
|
7
|
+
has(code) {
|
|
8
|
+
if (typeof code !== 'string') {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return this._raw[code] !== undefined;
|
|
12
|
+
}
|
|
13
|
+
/** @inheritDoc */
|
|
14
|
+
getRaw(code) {
|
|
15
|
+
if (typeof code !== 'string') {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return this._raw[code];
|
|
19
|
+
}
|
|
20
|
+
/** @inheritDoc */
|
|
21
|
+
getName(code) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
return (_b = (_a = this.getRaw(code)) === null || _a === void 0 ? void 0 : _a.n) !== null && _b !== void 0 ? _b : code;
|
|
24
|
+
}
|
|
25
|
+
/** @inheritDoc */
|
|
26
|
+
getAll() {
|
|
27
|
+
return this.codes.map(code => this.get(code));
|
|
28
|
+
}
|
|
29
|
+
/** @inheritDoc */
|
|
30
|
+
getSelected(...codes) {
|
|
31
|
+
return codes.filter(code => this.codes.includes(code)).map(code => this.get(code));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.BaseLocalizationHandler = BaseLocalizationHandler;
|
|
35
|
+
//# sourceMappingURL=base-localization.handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-localization.handler.js","sourceRoot":"","sources":["../../src/base/base-localization.handler.ts"],"names":[],"mappings":";;;AAEA,kBAAkB;AAClB,MAAsB,uBAAuB;IASzC,kBAAkB;IAClB,GAAG,CAAC,IAAO;QACP,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC;IACzC,CAAC;IAED,kBAAkB;IAClB,MAAM,CAAC,IAAO;QACV,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,kBAAkB;IAClB,OAAO,CAAC,IAAO;;QACX,OAAO,MAAA,MAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,0CAAE,CAAC,mCAAI,IAAI,CAAC;IACxC,CAAC;IAED,kBAAkB;IAClB,MAAM;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAClD,CAAC;IAKD,kBAAkB;IAClB,WAAW,CAAC,GAAG,KAAe;QAC1B,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IACvF,CAAC;CACJ;AAzCD,0DAyCC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./index.types"), exports);
|
|
18
|
+
__exportStar(require("./base-localization.handler"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/base/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,8DAA4C"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface BaseLocalizationHandlerView<E extends string> {
|
|
2
|
+
code: E;
|
|
3
|
+
name: string;
|
|
4
|
+
}
|
|
5
|
+
export interface BaseLocalizationHandlerRaw {
|
|
6
|
+
n: string;
|
|
7
|
+
}
|
|
8
|
+
export interface BaseLocalizationHandlerLike<E extends string, W extends BaseLocalizationHandlerView<E>, R extends BaseLocalizationHandlerRaw> {
|
|
9
|
+
/**
|
|
10
|
+
* Returns all codes
|
|
11
|
+
*
|
|
12
|
+
* @type {Array<string>} - codes
|
|
13
|
+
* */
|
|
14
|
+
readonly codes: ReadonlyArray<E>;
|
|
15
|
+
/**
|
|
16
|
+
* Has given code?
|
|
17
|
+
*
|
|
18
|
+
* @param {string} code - code
|
|
19
|
+
* @return {boolean} - exists or not
|
|
20
|
+
* */
|
|
21
|
+
has(code: E): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Returns raw record for given code
|
|
24
|
+
* - If it does not exist then returns undefined
|
|
25
|
+
*
|
|
26
|
+
* @param {string} code - code
|
|
27
|
+
* @return {BaseLocalizationHandlerRaw} - raw record
|
|
28
|
+
* */
|
|
29
|
+
getRaw(code: E): R;
|
|
30
|
+
/**
|
|
31
|
+
* Returns name for given code
|
|
32
|
+
*
|
|
33
|
+
* @param {string} code - code
|
|
34
|
+
* @return {string} - name
|
|
35
|
+
* */
|
|
36
|
+
getName(code: E): string;
|
|
37
|
+
/**
|
|
38
|
+
* Returns view object for given code
|
|
39
|
+
*
|
|
40
|
+
* @param {string} code - code
|
|
41
|
+
* @return {BaseLocalizationHandlerView} - view object
|
|
42
|
+
* */
|
|
43
|
+
get(code: E): W;
|
|
44
|
+
/**
|
|
45
|
+
* Returns view objects for given codes
|
|
46
|
+
*
|
|
47
|
+
* @param {...string} codes - codes
|
|
48
|
+
* @return {Array<BaseLocalizationHandlerView>} - view objects
|
|
49
|
+
* */
|
|
50
|
+
getSelected(...codes: Array<E>): Array<W>;
|
|
51
|
+
/**
|
|
52
|
+
* Returns all view objects
|
|
53
|
+
*
|
|
54
|
+
* @return {Array<BaseLocalizationHandlerView>} - view objects
|
|
55
|
+
* */
|
|
56
|
+
getAll(): Array<W>;
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.types.js","sourceRoot":"","sources":["../../src/base/index.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./index.types"), exports);
|
|
18
|
+
__exportStar(require("./localization.config"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,wDAAsC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BuilderAny } from "@leyyo/builder/dist/types";
|
|
2
|
+
import { LocaleCode } from "../locale";
|
|
3
|
+
import { LanguageCode } from "../language";
|
|
4
|
+
import { CountryCode } from "../country";
|
|
5
|
+
export interface LocalizationConfigLike {
|
|
6
|
+
readonly authorizationKeys: string[];
|
|
7
|
+
readonly applicationKeys: string[];
|
|
8
|
+
readonly correlationKeys: string[];
|
|
9
|
+
readonly refererKeys: string[];
|
|
10
|
+
readonly userAgentKeys: string[];
|
|
11
|
+
readonly acceptLanguageKeys: string[];
|
|
12
|
+
readonly ipAddressKeys: string[];
|
|
13
|
+
readonly applicationDelimiter: string;
|
|
14
|
+
readonly localeReplacer: ReplacerLike<string, LocaleCode>;
|
|
15
|
+
readonly languageReplacer: ReplacerLike<LanguageCode, LanguageCode>;
|
|
16
|
+
readonly countryReplacer: ReplacerLike<CountryCode, CountryCode>;
|
|
17
|
+
builder(): BuilderAny<LocalizationConfigOmit>;
|
|
18
|
+
}
|
|
19
|
+
export type ReplacerLike<T extends string, V> = {
|
|
20
|
+
[K in T]?: V;
|
|
21
|
+
};
|
|
22
|
+
export type LocalizationConfigOmit = Omit<LocalizationConfigLike, 'builder'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.types.js","sourceRoot":"","sources":["../../src/config/index.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.localizationConfig = void 0;
|
|
4
|
+
const builder_1 = require("@leyyo/builder");
|
|
5
|
+
class LocalizationConfig {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.authorizationKeys = ['authorization', 'api-key'];
|
|
8
|
+
this.applicationKeys = ['application', 'x-application'];
|
|
9
|
+
this.correlationKeys = ['x-correlation', 'x-correlation-id'];
|
|
10
|
+
this.refererKeys = ['x-fwd-referer', 'x-fwd-referrer', 'x-referer', 'x-referrer', 'referer', 'referrer'];
|
|
11
|
+
this.userAgentKeys = ['x-fwd-user-agent', 'x-user-agent', 'user-agent'];
|
|
12
|
+
this.acceptLanguageKeys = ['x-fwd-accept-language', 'x-accept-language', 'accept-language'];
|
|
13
|
+
this.ipAddressKeys = ['x-real-ip', 'x-client-ip', 'fastly-client-ip', 'true-client-ip', 'cf-connecting-ip', 'x-cluster-client-ip', 'x-forwarded-for'];
|
|
14
|
+
this.applicationDelimiter = ':';
|
|
15
|
+
this.countryReplacer = {};
|
|
16
|
+
this.languageReplacer = {};
|
|
17
|
+
this.localeReplacer = {};
|
|
18
|
+
}
|
|
19
|
+
builder() {
|
|
20
|
+
return builder_1.Builder.build(this)
|
|
21
|
+
.$setItem((key, value) => {
|
|
22
|
+
this[key] = value;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.localizationConfig = new LocalizationConfig();
|
|
27
|
+
//# sourceMappingURL=localization.config.js.map
|