@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.
- package/README.md +3 -3
- package/dist/base/base-localization.handler.d.ts +1 -1
- package/dist/base/base-localization.handler.js +18 -12
- package/dist/base/index.d.ts +2 -2
- package/dist/base/index.js +2 -19
- package/dist/base/index.types.js +1 -3
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +2 -19
- package/dist/config/index.types.d.ts +3 -5
- package/dist/config/index.types.js +1 -3
- package/dist/config/localization.config.d.ts +1 -1
- package/dist/config/localization.config.js +33 -21
- package/dist/country/country.handler.d.ts +1 -1
- package/dist/country/country.handler.js +13 -23
- package/dist/country/country.map.d.ts +2 -2
- package/dist/country/country.map.js +252 -256
- package/dist/country/index.d.ts +2 -3
- package/dist/country/index.js +2 -20
- package/dist/country/index.types.d.ts +2 -3
- package/dist/country/index.types.js +1 -3
- package/dist/exchange/exchange.handler.d.ts +1 -1
- package/dist/exchange/exchange.handler.js +14 -25
- package/dist/exchange/exchange.map.d.ts +2 -2
- package/dist/exchange/exchange.map.js +36 -9
- package/dist/exchange/index.d.ts +2 -3
- package/dist/exchange/index.js +2 -20
- package/dist/exchange/index.types.d.ts +2 -3
- package/dist/exchange/index.types.js +1 -3
- package/dist/index.d.ts +11 -7
- package/dist/index.foretell.d.ts +1 -0
- package/dist/index.foretell.js +19 -0
- package/dist/index.js +11 -24
- package/dist/index.loader.d.ts +1 -0
- package/dist/index.loader.js +13 -0
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +2 -5
- package/dist/language/index.d.ts +2 -3
- package/dist/language/index.js +2 -20
- package/dist/language/index.types.d.ts +2 -2
- package/dist/language/index.types.js +1 -3
- package/dist/language/language.handler.d.ts +1 -11
- package/dist/language/language.handler.js +13 -21
- package/dist/language/language.map.d.ts +2 -2
- package/dist/language/language.map.js +185 -189
- package/dist/literal/browser-type.d.ts +7 -0
- package/dist/literal/browser-type.js +2 -0
- package/dist/{country → literal}/country-code.d.ts +1 -1
- package/dist/literal/country-code.js +257 -0
- package/dist/literal/cpu-architecture.d.ts +7 -0
- package/dist/literal/cpu-architecture.js +20 -0
- package/dist/literal/device-type.d.ts +7 -0
- package/dist/literal/device-type.js +11 -0
- package/dist/literal/engine-type.d.ts +7 -0
- package/dist/literal/engine-type.js +23 -0
- package/dist/{exchange → literal}/exchange-code.d.ts +1 -1
- package/dist/literal/exchange-code.js +157 -0
- package/dist/literal/index.d.ts +9 -0
- package/dist/literal/index.js +9 -0
- package/dist/{language → literal}/language-code.d.ts +1 -1
- package/dist/literal/language-code.js +187 -0
- package/dist/{locale → literal}/locale-code.d.ts +1 -1
- package/dist/literal/locale-code.js +199 -0
- package/dist/{timezone → literal}/timezone-code.d.ts +1 -1
- package/dist/literal/timezone-code.js +605 -0
- package/dist/locale/index.d.ts +2 -3
- package/dist/locale/index.js +2 -20
- package/dist/locale/index.types.d.ts +2 -4
- package/dist/locale/index.types.js +1 -3
- package/dist/locale/locale.handler.d.ts +1 -17
- package/dist/locale/locale.handler.js +17 -28
- package/dist/locale/locale.map.d.ts +2 -2
- package/dist/locale/locale.map.js +84 -88
- package/dist/parser/index.d.ts +2 -2
- package/dist/parser/index.js +2 -19
- package/dist/parser/index.types.d.ts +4 -24
- package/dist/parser/index.types.js +1 -3
- package/dist/parser/localization.parser.d.ts +1 -1
- package/dist/parser/localization.parser.js +112 -111
- package/dist/timezone/index.d.ts +2 -3
- package/dist/timezone/index.js +2 -20
- package/dist/timezone/index.types.d.ts +2 -3
- package/dist/timezone/index.types.js +1 -3
- package/dist/timezone/timezone.handler.d.ts +1 -1
- package/dist/timezone/timezone.handler.js +21 -24
- package/dist/timezone/timezone.map.d.ts +2 -2
- package/dist/timezone/timezone.map.js +603 -607
- package/package.json +23 -23
- package/dist/base/base-localization.handler.js.map +0 -1
- package/dist/base/index.js.map +0 -1
- package/dist/base/index.types.js.map +0 -1
- package/dist/config/index.js.map +0 -1
- package/dist/config/index.types.js.map +0 -1
- package/dist/config/localization.config.js.map +0 -1
- package/dist/country/country-code.js +0 -19
- package/dist/country/country-code.js.map +0 -1
- package/dist/country/country.handler.js.map +0 -1
- package/dist/country/country.map.js.map +0 -1
- package/dist/country/index.js.map +0 -1
- package/dist/country/index.types.js.map +0 -1
- package/dist/exchange/exchange-code.js +0 -23
- package/dist/exchange/exchange-code.js.map +0 -1
- package/dist/exchange/exchange.handler.js.map +0 -1
- package/dist/exchange/exchange.map.js.map +0 -1
- package/dist/exchange/index.js.map +0 -1
- package/dist/exchange/index.types.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/internal.js.map +0 -1
- package/dist/language/index.js.map +0 -1
- package/dist/language/index.types.js.map +0 -1
- package/dist/language/language-code.js +0 -33
- package/dist/language/language-code.js.map +0 -1
- package/dist/language/language.handler.js.map +0 -1
- package/dist/language/language.map.js.map +0 -1
- package/dist/locale/index.js.map +0 -1
- package/dist/locale/index.types.js.map +0 -1
- package/dist/locale/locale-code.js +0 -25
- package/dist/locale/locale-code.js.map +0 -1
- package/dist/locale/locale.handler.js.map +0 -1
- package/dist/locale/locale.map.js.map +0 -1
- package/dist/parser/index.js.map +0 -1
- package/dist/parser/index.types.js.map +0 -1
- package/dist/parser/localization.parser.js.map +0 -1
- package/dist/timezone/index.js.map +0 -1
- package/dist/timezone/index.types.js.map +0 -1
- package/dist/timezone/timezone-code.js +0 -109
- package/dist/timezone/timezone-code.js.map +0 -1
- package/dist/timezone/timezone.handler.js.map +0 -1
- package/dist/timezone/timezone.map.js.map +0 -1
|
@@ -1,45 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 =
|
|
51
|
-
const token = this.
|
|
52
|
-
const acceptLanguage = this.
|
|
53
|
-
const ipAddress = this.
|
|
54
|
-
const application = this.
|
|
55
|
-
const referer = this.
|
|
56
|
-
const userAgent = this.
|
|
57
|
-
const correlationId = this.
|
|
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
|
-
|
|
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 ?
|
|
109
|
-
case
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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 &&
|
|
147
|
-
effective =
|
|
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
|
-
|
|
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 (!
|
|
176
|
+
if (!localizationConfig.applicationDelimiter) {
|
|
174
177
|
return;
|
|
175
178
|
}
|
|
176
|
-
if (!ctx.application.header.indexOf(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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:
|
|
257
|
-
vendor:
|
|
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 ===
|
|
265
|
+
if (result && typeof result === "object") {
|
|
265
266
|
ctx.agent.browser = {
|
|
266
|
-
name:
|
|
267
|
-
major:
|
|
267
|
+
name: result.browser?.name,
|
|
268
|
+
major: result.browser?.version,
|
|
268
269
|
};
|
|
269
270
|
ctx.agent.engine = {
|
|
270
|
-
name:
|
|
271
|
-
version:
|
|
271
|
+
name: result.engine?.name,
|
|
272
|
+
version: result.engine?.version,
|
|
272
273
|
};
|
|
273
274
|
ctx.agent.os = {
|
|
274
|
-
name:
|
|
275
|
-
version:
|
|
275
|
+
name: result.os?.name,
|
|
276
|
+
version: result.os?.version,
|
|
276
277
|
};
|
|
277
278
|
ctx.agent.device = {
|
|
278
|
-
vendor:
|
|
279
|
-
type:
|
|
280
|
-
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:
|
|
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
|
-
|
|
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 ===
|
|
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 =
|
|
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 (!
|
|
317
|
-
const langs =
|
|
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 =
|
|
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(
|
|
335
|
-
|
|
336
|
-
|
|
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 !==
|
|
345
|
+
if (typeof quality !== "string") {
|
|
344
346
|
return [lang, 1];
|
|
345
347
|
}
|
|
346
348
|
try {
|
|
347
|
-
return [lang, quality ? parseFloat(quality.split(
|
|
349
|
+
return [lang, quality ? parseFloat(quality.split("=")[1]) : 1.0];
|
|
348
350
|
}
|
|
349
|
-
catch (
|
|
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
|
-
|
|
363
|
-
//# sourceMappingURL=localization.parser.js.map
|
|
364
|
+
export const localizationParser = new LocalizationParser();
|
package/dist/timezone/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from './timezone.handler';
|
|
1
|
+
export * from "./index.types.js";
|
|
2
|
+
export * from "./timezone.handler.js";
|
package/dist/timezone/index.js
CHANGED
|
@@ -1,20 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
2
|
-
import
|
|
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,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { TimezoneHandlerLike } from "./index.types.js";
|
|
2
2
|
export declare const timezoneHandler: TimezoneHandlerLike;
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
28
|
-
dst: item
|
|
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
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
2
|
-
import
|
|
1
|
+
import { TimezoneRaw } from "./index.types.js";
|
|
2
|
+
import { TimezoneCode } from "../literal/index.js";
|
|
3
3
|
export declare const timezoneMap: Record<TimezoneCode, TimezoneRaw>;
|