@leyyo/localization 1.1.1 → 1.1.3

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.
Files changed (128) hide show
  1. package/README.md +3 -3
  2. package/dist/base/base-localization.handler.d.ts +1 -1
  3. package/dist/base/base-localization.handler.js +18 -12
  4. package/dist/base/index.d.ts +2 -2
  5. package/dist/base/index.js +2 -19
  6. package/dist/base/index.types.js +1 -3
  7. package/dist/config/index.d.ts +2 -2
  8. package/dist/config/index.js +2 -19
  9. package/dist/config/index.types.d.ts +3 -5
  10. package/dist/config/index.types.js +1 -3
  11. package/dist/config/localization.config.d.ts +1 -1
  12. package/dist/config/localization.config.js +33 -21
  13. package/dist/country/country.handler.d.ts +1 -1
  14. package/dist/country/country.handler.js +13 -23
  15. package/dist/country/country.map.d.ts +2 -2
  16. package/dist/country/country.map.js +252 -256
  17. package/dist/country/index.d.ts +2 -3
  18. package/dist/country/index.js +2 -20
  19. package/dist/country/index.types.d.ts +2 -3
  20. package/dist/country/index.types.js +1 -3
  21. package/dist/exchange/exchange.handler.d.ts +1 -1
  22. package/dist/exchange/exchange.handler.js +14 -25
  23. package/dist/exchange/exchange.map.d.ts +2 -2
  24. package/dist/exchange/exchange.map.js +36 -9
  25. package/dist/exchange/index.d.ts +2 -3
  26. package/dist/exchange/index.js +2 -20
  27. package/dist/exchange/index.types.d.ts +2 -3
  28. package/dist/exchange/index.types.js +1 -3
  29. package/dist/index.d.ts +11 -7
  30. package/dist/index.foretell.d.ts +1 -0
  31. package/dist/index.foretell.js +19 -0
  32. package/dist/index.js +11 -24
  33. package/dist/index.loader.d.ts +1 -0
  34. package/dist/index.loader.js +13 -0
  35. package/dist/internal.d.ts +1 -1
  36. package/dist/internal.js +2 -5
  37. package/dist/language/index.d.ts +2 -3
  38. package/dist/language/index.js +2 -20
  39. package/dist/language/index.types.d.ts +2 -2
  40. package/dist/language/index.types.js +1 -3
  41. package/dist/language/language.handler.d.ts +1 -11
  42. package/dist/language/language.handler.js +13 -21
  43. package/dist/language/language.map.d.ts +2 -2
  44. package/dist/language/language.map.js +185 -189
  45. package/dist/literal/browser-type.d.ts +7 -0
  46. package/dist/literal/browser-type.js +2 -0
  47. package/dist/{country → literal}/country-code.d.ts +1 -1
  48. package/dist/literal/country-code.js +257 -0
  49. package/dist/literal/cpu-architecture.d.ts +7 -0
  50. package/dist/literal/cpu-architecture.js +20 -0
  51. package/dist/literal/device-type.d.ts +7 -0
  52. package/dist/literal/device-type.js +11 -0
  53. package/dist/literal/engine-type.d.ts +7 -0
  54. package/dist/literal/engine-type.js +23 -0
  55. package/dist/{exchange → literal}/exchange-code.d.ts +1 -1
  56. package/dist/literal/exchange-code.js +157 -0
  57. package/dist/literal/index.d.ts +9 -0
  58. package/dist/literal/index.js +9 -0
  59. package/dist/{language → literal}/language-code.d.ts +1 -1
  60. package/dist/literal/language-code.js +187 -0
  61. package/dist/{locale → literal}/locale-code.d.ts +1 -1
  62. package/dist/literal/locale-code.js +199 -0
  63. package/dist/{timezone → literal}/timezone-code.d.ts +1 -1
  64. package/dist/literal/timezone-code.js +605 -0
  65. package/dist/locale/index.d.ts +2 -3
  66. package/dist/locale/index.js +2 -20
  67. package/dist/locale/index.types.d.ts +2 -4
  68. package/dist/locale/index.types.js +1 -3
  69. package/dist/locale/locale.handler.d.ts +1 -17
  70. package/dist/locale/locale.handler.js +17 -28
  71. package/dist/locale/locale.map.d.ts +2 -2
  72. package/dist/locale/locale.map.js +84 -88
  73. package/dist/parser/index.d.ts +2 -2
  74. package/dist/parser/index.js +2 -19
  75. package/dist/parser/index.types.d.ts +4 -24
  76. package/dist/parser/index.types.js +1 -3
  77. package/dist/parser/localization.parser.d.ts +1 -1
  78. package/dist/parser/localization.parser.js +112 -111
  79. package/dist/timezone/index.d.ts +2 -3
  80. package/dist/timezone/index.js +2 -20
  81. package/dist/timezone/index.types.d.ts +2 -3
  82. package/dist/timezone/index.types.js +1 -3
  83. package/dist/timezone/timezone.handler.d.ts +1 -1
  84. package/dist/timezone/timezone.handler.js +21 -24
  85. package/dist/timezone/timezone.map.d.ts +2 -2
  86. package/dist/timezone/timezone.map.js +603 -607
  87. package/package.json +23 -23
  88. package/dist/base/base-localization.handler.js.map +0 -1
  89. package/dist/base/index.js.map +0 -1
  90. package/dist/base/index.types.js.map +0 -1
  91. package/dist/config/index.js.map +0 -1
  92. package/dist/config/index.types.js.map +0 -1
  93. package/dist/config/localization.config.js.map +0 -1
  94. package/dist/country/country-code.js +0 -19
  95. package/dist/country/country-code.js.map +0 -1
  96. package/dist/country/country.handler.js.map +0 -1
  97. package/dist/country/country.map.js.map +0 -1
  98. package/dist/country/index.js.map +0 -1
  99. package/dist/country/index.types.js.map +0 -1
  100. package/dist/exchange/exchange-code.js +0 -23
  101. package/dist/exchange/exchange-code.js.map +0 -1
  102. package/dist/exchange/exchange.handler.js.map +0 -1
  103. package/dist/exchange/exchange.map.js.map +0 -1
  104. package/dist/exchange/index.js.map +0 -1
  105. package/dist/exchange/index.types.js.map +0 -1
  106. package/dist/index.js.map +0 -1
  107. package/dist/internal.js.map +0 -1
  108. package/dist/language/index.js.map +0 -1
  109. package/dist/language/index.types.js.map +0 -1
  110. package/dist/language/language-code.js +0 -33
  111. package/dist/language/language-code.js.map +0 -1
  112. package/dist/language/language.handler.js.map +0 -1
  113. package/dist/language/language.map.js.map +0 -1
  114. package/dist/locale/index.js.map +0 -1
  115. package/dist/locale/index.types.js.map +0 -1
  116. package/dist/locale/locale-code.js +0 -25
  117. package/dist/locale/locale-code.js.map +0 -1
  118. package/dist/locale/locale.handler.js.map +0 -1
  119. package/dist/locale/locale.map.js.map +0 -1
  120. package/dist/parser/index.js.map +0 -1
  121. package/dist/parser/index.types.js.map +0 -1
  122. package/dist/parser/localization.parser.js.map +0 -1
  123. package/dist/timezone/index.js.map +0 -1
  124. package/dist/timezone/index.types.js.map +0 -1
  125. package/dist/timezone/timezone-code.js +0 -109
  126. package/dist/timezone/timezone-code.js.map +0 -1
  127. package/dist/timezone/timezone.handler.js.map +0 -1
  128. package/dist/timezone/timezone.map.js.map +0 -1
@@ -1,45 +1,9 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.localizationParser = void 0;
37
- const config_1 = require("../config");
38
- const uaParser = __importStar(require("ua-parser-js"));
39
- const geoIp = __importStar(require("geoip-lite"));
40
- const timezone_1 = require("../timezone");
41
- const country_1 = require("../country");
42
- const exchange_1 = require("../exchange");
1
+ import { localizationConfig } from "../config/index.js";
2
+ import * as uaParser from "ua-parser-js";
3
+ import * as geoIp from "geoip-lite";
4
+ import { exchangeHandler } from "../exchange/index.js";
5
+ import { timezoneHandler } from "../timezone/index.js";
6
+ import { countryHandler } from "../country/index.js";
43
7
  class LocalizationParser {
44
8
  /**
45
9
  * Parses header values
@@ -47,14 +11,14 @@ class LocalizationParser {
47
11
  parse(req) {
48
12
  const ctx = {};
49
13
  try {
50
- const opt = config_1.localizationConfig;
51
- const token = this._readFromHeader(req === null || req === void 0 ? void 0 : req.headers, ...opt.authorizationKeys);
52
- const acceptLanguage = this._readFromHeader(req === null || req === void 0 ? void 0 : req.headers, ...opt.acceptLanguageKeys);
53
- const ipAddress = this._readFromHeader(req === null || req === void 0 ? void 0 : req.headers, ...opt.ipAddressKeys);
54
- const application = this._readFromHeader(req === null || req === void 0 ? void 0 : req.headers, ...opt.applicationKeys);
55
- const referer = this._readFromHeader(req === null || req === void 0 ? void 0 : req.headers, ...opt.refererKeys);
56
- const userAgent = this._readFromHeader(req === null || req === void 0 ? void 0 : req.headers, ...opt.userAgentKeys);
57
- const correlationId = this._readFromHeader(req === null || req === void 0 ? void 0 : req.headers, ...opt.correlationKeys);
14
+ const opt = localizationConfig;
15
+ const token = this._allFromHeader(req?.headers, ...opt.authorizationKeys);
16
+ const acceptLanguage = this._anyFromHeader(req?.headers, ...opt.acceptLanguageKeys);
17
+ const ipAddress = this._anyFromHeader(req?.headers, ...opt.ipAddressKeys);
18
+ const application = this._anyFromHeader(req?.headers, ...opt.applicationKeys);
19
+ const referer = this._anyFromHeader(req?.headers, ...opt.refererKeys);
20
+ const userAgent = this._anyFromHeader(req?.headers, ...opt.userAgentKeys);
21
+ const correlationId = this._anyFromHeader(req?.headers, ...opt.correlationKeys);
58
22
  if (token) {
59
23
  ctx.token = token;
60
24
  }
@@ -92,8 +56,11 @@ class LocalizationParser {
92
56
  /**
93
57
  * Get value from header by multiple header keys
94
58
  * */
95
- _readFromHeader(headers, ...keys) {
59
+ _anyFromHeader(headers, ...keys) {
96
60
  for (const key of keys) {
61
+ if (headers[key] === undefined) {
62
+ continue;
63
+ }
97
64
  let value = headers[key];
98
65
  switch (typeof value) {
99
66
  case "string":
@@ -105,8 +72,8 @@ class LocalizationParser {
105
72
  case "number":
106
73
  return { header: value.toString(10), key };
107
74
  case "boolean":
108
- return { header: value ? 'true' : 'false', key };
109
- case 'object':
75
+ return { header: value ? "true" : "false", key };
76
+ case "object":
110
77
  if (Array.isArray(value) && value.length > 0) {
111
78
  for (let val of value) {
112
79
  val = val.trim();
@@ -120,20 +87,57 @@ class LocalizationParser {
120
87
  }
121
88
  return undefined;
122
89
  }
90
+ /**
91
+ * Get value from header by multiple header keys
92
+ * */
93
+ _allFromHeader(headers, ...keys) {
94
+ const result = {};
95
+ for (const key of keys) {
96
+ if (headers[key] === undefined) {
97
+ continue;
98
+ }
99
+ let value = headers[key];
100
+ switch (typeof value) {
101
+ case "string":
102
+ value = value.trim();
103
+ if (value) {
104
+ result[key] = value;
105
+ }
106
+ break;
107
+ case "number":
108
+ result[key] = value.toString(10);
109
+ break;
110
+ case "boolean":
111
+ result[key] = value ? "true" : "false";
112
+ break;
113
+ case "object":
114
+ if (Array.isArray(value) && value.length > 0) {
115
+ for (let val of value) {
116
+ val = val.trim();
117
+ if (val) {
118
+ result[key] = val;
119
+ break;
120
+ }
121
+ }
122
+ }
123
+ break;
124
+ }
125
+ }
126
+ return result;
127
+ }
123
128
  _processAcceptLanguage(ctx) {
124
- var _a;
125
- if (!((_a = ctx.language) === null || _a === void 0 ? void 0 : _a.header)) {
129
+ if (!ctx.language?.header) {
126
130
  return;
127
131
  }
128
- let locale = ctx.language.header.split(',').pop().trim();
129
- if (locale === '') {
132
+ let locale = ctx.language.header.split(",").pop().trim();
133
+ if (locale === "") {
130
134
  locale = undefined;
131
135
  }
132
136
  let code;
133
137
  if (locale) {
134
- if (locale.includes('-')) {
135
- code = locale.split('-').shift().trim();
136
- if (code === '') {
138
+ if (locale.includes("-")) {
139
+ code = locale.split("-").shift().trim();
140
+ if (code === "") {
137
141
  code = undefined;
138
142
  }
139
143
  }
@@ -143,8 +147,8 @@ class LocalizationParser {
143
147
  code = weights.shift()[0];
144
148
  }
145
149
  let effective;
146
- if (code && config_1.localizationConfig.languageReplacer[code] !== undefined) {
147
- effective = config_1.localizationConfig.languageReplacer[code];
150
+ if (code && localizationConfig.languageReplacer[code] !== undefined) {
151
+ effective = localizationConfig.languageReplacer[code];
148
152
  }
149
153
  if (locale) {
150
154
  ctx.language.locale = locale;
@@ -157,7 +161,7 @@ class LocalizationParser {
157
161
  }
158
162
  if (weights.length > 0) {
159
163
  ctx.language.weighted = {};
160
- weights.forEach(tuple => {
164
+ weights.forEach((tuple) => {
161
165
  ctx.language.weighted[tuple[0]] = tuple[1];
162
166
  });
163
167
  }
@@ -166,24 +170,23 @@ class LocalizationParser {
166
170
  * Builds application instance
167
171
  * */
168
172
  _processApplication(ctx) {
169
- var _a;
170
- if (!((_a = ctx.application) === null || _a === void 0 ? void 0 : _a.header)) {
173
+ if (!ctx.application?.header) {
171
174
  return;
172
175
  }
173
- if (!config_1.localizationConfig.applicationDelimiter) {
176
+ if (!localizationConfig.applicationDelimiter) {
174
177
  return;
175
178
  }
176
- if (!ctx.application.header.indexOf(config_1.localizationConfig.applicationDelimiter)) {
179
+ if (!ctx.application.header.indexOf(localizationConfig.applicationDelimiter)) {
177
180
  return;
178
181
  }
179
182
  // com.company.app:2.3.0
180
- const parts = ctx.application.header.split(config_1.localizationConfig.applicationDelimiter);
183
+ const parts = ctx.application.header.split(localizationConfig.applicationDelimiter);
181
184
  ctx.application.name = parts[0].trim();
182
- ctx.application.version = parts[1] ? parts[1].trim() : '';
183
- if (ctx.application.name === '') {
185
+ ctx.application.version = parts[1] ? parts[1].trim() : "";
186
+ if (ctx.application.name === "") {
184
187
  delete ctx.application.name;
185
188
  }
186
- if (ctx.application.version === '') {
189
+ if (ctx.application.version === "") {
187
190
  delete ctx.application.version;
188
191
  }
189
192
  }
@@ -195,10 +198,10 @@ class LocalizationParser {
195
198
  if (!val) {
196
199
  return undefined;
197
200
  }
198
- if (!val.indexOf(',')) {
201
+ if (!val.indexOf(",")) {
199
202
  return val;
200
203
  }
201
- const parts = val.split(',');
204
+ const parts = val.split(",");
202
205
  for (let part of parts) {
203
206
  part = part ? String(part) : undefined;
204
207
  if (part) {
@@ -229,8 +232,7 @@ class LocalizationParser {
229
232
  * Builds referer instance
230
233
  * */
231
234
  _processReferer(ctx) {
232
- var _a;
233
- if (!((_a = ctx.referer) === null || _a === void 0 ? void 0 : _a.header)) {
235
+ if (!ctx.referer?.header) {
234
236
  return;
235
237
  }
236
238
  ctx.referer.domain = this._findDomain(ctx.referer.header);
@@ -242,45 +244,44 @@ class LocalizationParser {
242
244
  * Builds corresponding instance via user agent
243
245
  * */
244
246
  _parseUserAgent(ctx) {
245
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
246
- if (!((_a = ctx.agent) === null || _a === void 0 ? void 0 : _a.header)) {
247
+ if (!ctx.agent?.header) {
247
248
  return;
248
249
  }
249
- if (ctx.agent.header.startsWith('PostmanRuntime')) {
250
- const parts = ctx.agent.header.split('/');
250
+ if (ctx.agent.header.startsWith("PostmanRuntime")) {
251
+ const parts = ctx.agent.header.split("/");
251
252
  ctx.agent.browser = {
252
253
  name: parts[0],
253
254
  major: parts[1],
254
255
  };
255
256
  ctx.agent.device = {
256
- type: 'testing',
257
- vendor: 'Postman',
257
+ type: "testing",
258
+ vendor: "Postman",
258
259
  };
259
260
  return;
260
261
  }
261
262
  const parser = new uaParser.UAParser();
262
263
  parser.setUA(ctx.agent.header);
263
264
  const result = parser.getResult();
264
- if (result && typeof result === 'object') {
265
+ if (result && typeof result === "object") {
265
266
  ctx.agent.browser = {
266
- name: (_b = result.browser) === null || _b === void 0 ? void 0 : _b.name,
267
- major: (_c = result.browser) === null || _c === void 0 ? void 0 : _c.version,
267
+ name: result.browser?.name,
268
+ major: result.browser?.version,
268
269
  };
269
270
  ctx.agent.engine = {
270
- name: (_d = result.engine) === null || _d === void 0 ? void 0 : _d.name,
271
- version: (_e = result.engine) === null || _e === void 0 ? void 0 : _e.version,
271
+ name: result.engine?.name,
272
+ version: result.engine?.version,
272
273
  };
273
274
  ctx.agent.os = {
274
- name: (_f = result.os) === null || _f === void 0 ? void 0 : _f.name,
275
- version: (_g = result.os) === null || _g === void 0 ? void 0 : _g.version,
275
+ name: result.os?.name,
276
+ version: result.os?.version,
276
277
  };
277
278
  ctx.agent.device = {
278
- vendor: (_h = result.device) === null || _h === void 0 ? void 0 : _h.vendor,
279
- type: (_j = result.device) === null || _j === void 0 ? void 0 : _j.type,
280
- model: (_k = result.device) === null || _k === void 0 ? void 0 : _k.model,
279
+ vendor: result.device?.vendor,
280
+ type: result.device?.type,
281
+ model: result.device?.model,
281
282
  };
282
283
  ctx.agent.cpu = {
283
- architecture: (_l = result.cpu) === null || _l === void 0 ? void 0 : _l.architecture,
284
+ architecture: result.cpu?.architecture,
284
285
  };
285
286
  }
286
287
  }
@@ -288,19 +289,18 @@ class LocalizationParser {
288
289
  * Builds location instance
289
290
  * */
290
291
  _processLocation(ctx) {
291
- var _a, _b;
292
- if (!((_a = ctx.location) === null || _a === void 0 ? void 0 : _a.ip)) {
292
+ if (!ctx.location?.ip) {
293
293
  return;
294
294
  }
295
295
  const geo = geoIp.lookup(ctx.location.ip);
296
- if (geo && typeof geo === 'object') {
296
+ if (geo && typeof geo === "object") {
297
297
  ctx.location.country = geo.country;
298
298
  ctx.location.timezone = geo.timezone;
299
299
  ctx.location.region = geo.region;
300
300
  ctx.location.city = geo.city;
301
301
  ctx.location.metro = geo.metro;
302
302
  if (ctx.location.timezone) {
303
- const raw = timezone_1.timezoneHandler.get(ctx.location.timezone);
303
+ const raw = timezoneHandler.get(ctx.location.timezone);
304
304
  if (raw) {
305
305
  ctx.location.timezone = raw.code;
306
306
  if (!ctx.location.country && Array.isArray(raw.countries)) {
@@ -313,8 +313,8 @@ class LocalizationParser {
313
313
  }
314
314
  }
315
315
  if (ctx.location.country) {
316
- if (!((_b = ctx.language) === null || _b === void 0 ? void 0 : _b.code)) {
317
- const langs = country_1.countryHandler.getLanguages(ctx.location.country);
316
+ if (!ctx.language?.code) {
317
+ const langs = countryHandler.getLanguages(ctx.location.country);
318
318
  if (Array.isArray(langs)) {
319
319
  if (!ctx.language) {
320
320
  ctx.language = { code: langs[0] };
@@ -324,40 +324,41 @@ class LocalizationParser {
324
324
  }
325
325
  }
326
326
  }
327
- const currencies = exchange_1.exchangeHandler.findByCountry(ctx.location.country);
327
+ const currencies = exchangeHandler.findByCountry(ctx.location.country);
328
328
  if (Array.isArray(currencies)) {
329
329
  ctx.location.exchange = currencies[0];
330
330
  }
331
331
  }
332
332
  }
333
333
  }
334
- _parseLangPart(parts) {
335
- let [lang, quality] = parts.split(';');
336
- if (typeof lang !== 'string') {
334
+ _parseLangPart(part) {
335
+ const parts = part.split(";");
336
+ let lang = parts.shift();
337
+ const quality = parts.shift();
338
+ if (typeof lang !== "string") {
337
339
  return undefined;
338
340
  }
339
341
  lang = lang.trim();
340
- if (lang === '') {
342
+ if (!lang) {
341
343
  return undefined;
342
344
  }
343
- if (typeof quality !== 'string') {
345
+ if (typeof quality !== "string") {
344
346
  return [lang, 1];
345
347
  }
346
348
  try {
347
- return [lang, quality ? parseFloat(quality.split('=')[1]) : 1.0];
349
+ return [lang, quality ? parseFloat(quality.split("=")[1]) : 1.0];
348
350
  }
349
- catch (e) {
351
+ catch (_e) {
350
352
  return [lang, 1];
351
353
  }
352
354
  }
353
355
  _parseAndSortLanguageTags(given) {
354
356
  return given
355
- .split(',')
356
- .map(p => this._parseLangPart(p.replace(/\s+/, '')))
357
- .filter(tuple => tuple !== undefined)
357
+ .split(",")
358
+ .map((p) => this._parseLangPart(p.replace(/\s+/, "")))
359
+ .filter((tuple) => tuple !== undefined)
358
360
  .sort((a, b) => b[1] - a[1]);
359
361
  }
360
362
  }
361
363
  // noinspection JSUnusedGlobalSymbols
362
- exports.localizationParser = new LocalizationParser();
363
- //# sourceMappingURL=localization.parser.js.map
364
+ export const localizationParser = new LocalizationParser();
@@ -1,3 +1,2 @@
1
- export * from './timezone-code';
2
- export * from './index.types';
3
- export * from './timezone.handler';
1
+ export * from "./index.types.js";
2
+ export * from "./timezone.handler.js";
@@ -1,20 +1,2 @@
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("./timezone-code"), exports);
18
- __exportStar(require("./index.types"), exports);
19
- __exportStar(require("./timezone.handler"), exports);
20
- //# sourceMappingURL=index.js.map
1
+ export * from "./index.types.js";
2
+ export * from "./timezone.handler.js";
@@ -1,6 +1,5 @@
1
- import type { TimezoneCode } from "./timezone-code";
2
- import type { BaseLocalizationHandlerLike, BaseLocalizationHandlerRaw, BaseLocalizationHandlerView } from "../base";
3
- import { CountryCode } from "../country";
1
+ import { CountryCode, TimezoneCode } from "../literal/index.js";
2
+ import { BaseLocalizationHandlerLike, BaseLocalizationHandlerRaw, BaseLocalizationHandlerView } from "../base/index.js";
4
3
  /**
5
4
  * Timezone raw format
6
5
  * @interface
@@ -1,3 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=index.types.js.map
1
+ export {};
@@ -1,2 +1,2 @@
1
- import type { TimezoneHandlerLike } from "./index.types";
1
+ import { TimezoneHandlerLike } from "./index.types.js";
2
2
  export declare const timezoneHandler: TimezoneHandlerLike;
@@ -1,18 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.timezoneHandler = void 0;
4
- const timezone_map_1 = require("./timezone.map");
5
- const timezone_code_1 = require("./timezone-code");
6
- const base_1 = require("../base");
1
+ import { timezoneMap } from "./timezone.map.js";
2
+ import { TimezoneCodeItems } from "../literal/index.js";
3
+ import { BaseLocalizationHandler } from "../base/index.js";
7
4
  /** @inheritDoc */
8
- class TimezoneHandler extends base_1.BaseLocalizationHandler {
9
- constructor() {
10
- super(...arguments);
11
- /** @inheritDoc */
12
- this._raw = timezone_map_1.timezoneMap;
13
- /** @inheritDoc */
14
- this.codes = timezone_code_1.TimezoneCodeItems;
15
- }
5
+ class TimezoneHandler extends BaseLocalizationHandler {
6
+ /** @inheritDoc */
7
+ _raw = timezoneMap;
8
+ /** @inheritDoc */
9
+ codes = TimezoneCodeItems;
16
10
  /** @inheritDoc */
17
11
  getHour(code, dst) {
18
12
  const hours = this.getHours(code);
@@ -24,8 +18,8 @@ class TimezoneHandler extends base_1.BaseLocalizationHandler {
24
18
  if (parent) {
25
19
  const item = this.getRaw(parent);
26
20
  return {
27
- sdt: item === null || item === void 0 ? void 0 : item.s,
28
- dst: item === null || item === void 0 ? void 0 : item.w,
21
+ sdt: item?.s,
22
+ dst: item?.w,
29
23
  };
30
24
  }
31
25
  return {
@@ -35,24 +29,29 @@ class TimezoneHandler extends base_1.BaseLocalizationHandler {
35
29
  }
36
30
  /** @inheritDoc */
37
31
  getParent(code) {
38
- var _a;
39
32
  const item = this.getRaw(code);
40
33
  if (!item) {
41
34
  return undefined;
42
35
  }
43
36
  if (item.p) {
44
- return (_a = this.getParent(this._raw[code].p)) !== null && _a !== void 0 ? _a : code;
37
+ return this.getParent(this._raw[code].p) ?? code;
45
38
  }
46
39
  return code;
47
40
  }
48
41
  /** @inheritDoc */
49
42
  get(code) {
50
- var _a;
51
43
  const item = this.getRaw(code);
52
44
  if (!item) {
53
45
  return { code, name: code, sdt: undefined, dst: undefined, parent: undefined, countries: [] };
54
46
  }
55
- return { code, name: item.n, sdt: item.s, dst: item.w, parent: item.p, countries: (_a = item.c) !== null && _a !== void 0 ? _a : [] };
47
+ return {
48
+ code,
49
+ name: item.n,
50
+ sdt: item.s,
51
+ dst: item.w,
52
+ parent: item.p,
53
+ countries: item.c ?? [],
54
+ };
56
55
  }
57
56
  /** @inheritDoc */
58
57
  getSdt(code) {
@@ -72,8 +71,7 @@ class TimezoneHandler extends base_1.BaseLocalizationHandler {
72
71
  }
73
72
  /** @inheritDoc */
74
73
  getCountries(code) {
75
- var _a, _b;
76
- return (_b = (_a = this.getRaw(code)) === null || _a === void 0 ? void 0 : _a.c) !== null && _b !== void 0 ? _b : [];
74
+ return this.getRaw(code)?.c ?? [];
77
75
  }
78
76
  /** @inheritDoc */
79
77
  isAlias(code) {
@@ -86,9 +84,8 @@ class TimezoneHandler extends base_1.BaseLocalizationHandler {
86
84
  }
87
85
  }
88
86
  // noinspection JSUnusedGlobalSymbols
89
- exports.timezoneHandler = new TimezoneHandler();
87
+ export const timezoneHandler = new TimezoneHandler();
90
88
  /*
91
89
  * @todo
92
90
  * - https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
93
91
  */
94
- //# sourceMappingURL=timezone.handler.js.map
@@ -1,3 +1,3 @@
1
- import type { TimezoneRaw } from "./index.types";
2
- import type { TimezoneCode } from "./timezone-code";
1
+ import { TimezoneRaw } from "./index.types.js";
2
+ import { TimezoneCode } from "../literal/index.js";
3
3
  export declare const timezoneMap: Record<TimezoneCode, TimezoneRaw>;