@catbee/utils 2.0.3 → 2.0.5
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/cache/index.cjs +36 -16
- package/cache/index.d.ts +6 -2
- package/cache/index.mjs +36 -16
- package/config/index.cjs +0 -5
- package/config/index.mjs +0 -5
- package/crypto/index.cjs +9 -1
- package/crypto/index.mjs +9 -1
- package/date/index.cjs +276 -0
- package/date/index.d.ts +44 -1
- package/date/index.mjs +273 -1
- package/error/index.cjs +58 -0
- package/error/index.d.ts +62 -0
- package/error/index.mjs +54 -0
- package/index.cjs +7 -0
- package/index.d.ts +1 -0
- package/index.mjs +1 -0
- package/logger/index.cjs +13 -12
- package/logger/index.d.ts +5 -5
- package/logger/index.mjs +13 -12
- package/package.json +6 -2
- package/server/index.cjs +129 -272
- package/server/index.d.ts +22 -59
- package/server/index.mjs +129 -272
- package/types/index.d.ts +0 -22
package/cache/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ var TTLCache = class {
|
|
|
33
33
|
__name(this, "TTLCache");
|
|
34
34
|
}
|
|
35
35
|
cache = /* @__PURE__ */ new Map();
|
|
36
|
+
pending = /* @__PURE__ */ new Map();
|
|
36
37
|
ttlMs;
|
|
37
38
|
maxSize;
|
|
38
39
|
cleanupInterval;
|
|
@@ -90,7 +91,7 @@ var TTLCache = class {
|
|
|
90
91
|
const entry = this.cache.get(key);
|
|
91
92
|
if (!entry) return void 0;
|
|
92
93
|
const now = Date.now();
|
|
93
|
-
if (now
|
|
94
|
+
if (now >= entry.expiresAt) {
|
|
94
95
|
this.cache.delete(key);
|
|
95
96
|
return void 0;
|
|
96
97
|
}
|
|
@@ -102,17 +103,31 @@ var TTLCache = class {
|
|
|
102
103
|
/**
|
|
103
104
|
* Retrieves or computes a value if it's not in the cache or has expired.
|
|
104
105
|
*
|
|
106
|
+
* Concurrent calls for the same key share the same producer promise,
|
|
107
|
+
* preventing duplicate computations while the value is being generated.
|
|
108
|
+
*
|
|
105
109
|
* @param key - The key to retrieve
|
|
106
110
|
* @param producer - Function to generate the value if not cached
|
|
107
111
|
* @param ttlMs - Optional custom TTL for the computed value
|
|
108
112
|
* @returns The cached or computed value
|
|
109
113
|
*/
|
|
110
114
|
async getOrCompute(key, producer, ttlMs) {
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
const cached = this.get(key);
|
|
116
|
+
if (cached !== void 0) {
|
|
117
|
+
return cached;
|
|
118
|
+
}
|
|
119
|
+
const pending = this.pending.get(key);
|
|
120
|
+
if (pending) {
|
|
121
|
+
return pending;
|
|
122
|
+
}
|
|
123
|
+
const promise = Promise.resolve().then(producer).then((value) => {
|
|
124
|
+
this.setWithTTL(key, value, ttlMs ?? this.ttlMs);
|
|
125
|
+
return value;
|
|
126
|
+
}).finally(() => {
|
|
127
|
+
this.pending.delete(key);
|
|
128
|
+
});
|
|
129
|
+
this.pending.set(key, promise);
|
|
130
|
+
return promise;
|
|
116
131
|
}
|
|
117
132
|
/**
|
|
118
133
|
* Checks if the key exists and hasn't expired.
|
|
@@ -174,7 +189,7 @@ var TTLCache = class {
|
|
|
174
189
|
let removed = 0;
|
|
175
190
|
const now = Date.now();
|
|
176
191
|
for (const [key, entry] of this.cache.entries()) {
|
|
177
|
-
if (now
|
|
192
|
+
if (now >= entry.expiresAt) {
|
|
178
193
|
this.cache.delete(key);
|
|
179
194
|
removed++;
|
|
180
195
|
}
|
|
@@ -188,7 +203,7 @@ var TTLCache = class {
|
|
|
188
203
|
*/
|
|
189
204
|
*entries() {
|
|
190
205
|
for (const [key, entry] of this.cache.entries()) {
|
|
191
|
-
if (Date.now()
|
|
206
|
+
if (Date.now() < entry.expiresAt) {
|
|
192
207
|
yield [
|
|
193
208
|
key,
|
|
194
209
|
entry.value
|
|
@@ -203,7 +218,7 @@ var TTLCache = class {
|
|
|
203
218
|
*/
|
|
204
219
|
*keys() {
|
|
205
220
|
for (const [key, entry] of this.cache.entries()) {
|
|
206
|
-
if (Date.now()
|
|
221
|
+
if (Date.now() < entry.expiresAt) {
|
|
207
222
|
yield key;
|
|
208
223
|
}
|
|
209
224
|
}
|
|
@@ -215,7 +230,7 @@ var TTLCache = class {
|
|
|
215
230
|
*/
|
|
216
231
|
*values() {
|
|
217
232
|
for (const entry of this.cache.values()) {
|
|
218
|
-
if (Date.now()
|
|
233
|
+
if (Date.now() < entry.expiresAt) {
|
|
219
234
|
yield entry.value;
|
|
220
235
|
}
|
|
221
236
|
}
|
|
@@ -231,12 +246,14 @@ var TTLCache = class {
|
|
|
231
246
|
const entry = this.cache.get(key);
|
|
232
247
|
if (!entry) return false;
|
|
233
248
|
const now = Date.now();
|
|
234
|
-
if (now
|
|
249
|
+
if (now >= entry.expiresAt) {
|
|
235
250
|
this.cache.delete(key);
|
|
236
251
|
return false;
|
|
237
252
|
}
|
|
238
253
|
entry.expiresAt = now + (ttlMs ?? this.ttlMs);
|
|
239
254
|
entry.lastAccessed = now;
|
|
255
|
+
this.cache.delete(key);
|
|
256
|
+
this.cache.set(key, entry);
|
|
240
257
|
return true;
|
|
241
258
|
}
|
|
242
259
|
/**
|
|
@@ -249,7 +266,7 @@ var TTLCache = class {
|
|
|
249
266
|
let expired = 0;
|
|
250
267
|
let valid = 0;
|
|
251
268
|
for (const entry of this.cache.values()) {
|
|
252
|
-
if (now
|
|
269
|
+
if (now >= entry.expiresAt) {
|
|
253
270
|
expired++;
|
|
254
271
|
} else {
|
|
255
272
|
valid++;
|
|
@@ -277,14 +294,17 @@ var TTLCache = class {
|
|
|
277
294
|
*/
|
|
278
295
|
evictLRU() {
|
|
279
296
|
const now = Date.now();
|
|
280
|
-
for (const [key, entry] of
|
|
281
|
-
if (now
|
|
297
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
298
|
+
if (now >= entry.expiresAt) {
|
|
282
299
|
this.cache.delete(key);
|
|
283
300
|
}
|
|
284
301
|
}
|
|
285
302
|
while (this.maxSize && this.cache.size > this.maxSize) {
|
|
286
|
-
const
|
|
287
|
-
|
|
303
|
+
const next = this.cache.keys().next();
|
|
304
|
+
if (next.done) {
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
this.cache.delete(next.value);
|
|
288
308
|
}
|
|
289
309
|
}
|
|
290
310
|
};
|
package/cache/index.d.ts
CHANGED
|
@@ -41,11 +41,12 @@ interface TTLCacheOptions {
|
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
43
|
* const cache = new TTLCache<string, number>({ ttlMs: 1000 });
|
|
44
|
-
* cache.set(
|
|
45
|
-
* const value = cache.get(
|
|
44
|
+
* cache.set('x', 123);
|
|
45
|
+
* const value = cache.get('x'); // 123
|
|
46
46
|
*/
|
|
47
47
|
declare class TTLCache<K, V> {
|
|
48
48
|
private readonly cache;
|
|
49
|
+
private readonly pending;
|
|
49
50
|
private readonly ttlMs;
|
|
50
51
|
private readonly maxSize?;
|
|
51
52
|
private cleanupInterval?;
|
|
@@ -78,6 +79,9 @@ declare class TTLCache<K, V> {
|
|
|
78
79
|
/**
|
|
79
80
|
* Retrieves or computes a value if it's not in the cache or has expired.
|
|
80
81
|
*
|
|
82
|
+
* Concurrent calls for the same key share the same producer promise,
|
|
83
|
+
* preventing duplicate computations while the value is being generated.
|
|
84
|
+
*
|
|
81
85
|
* @param key - The key to retrieve
|
|
82
86
|
* @param producer - Function to generate the value if not cached
|
|
83
87
|
* @param ttlMs - Optional custom TTL for the computed value
|
package/cache/index.mjs
CHANGED
|
@@ -31,6 +31,7 @@ var TTLCache = class {
|
|
|
31
31
|
__name(this, "TTLCache");
|
|
32
32
|
}
|
|
33
33
|
cache = /* @__PURE__ */ new Map();
|
|
34
|
+
pending = /* @__PURE__ */ new Map();
|
|
34
35
|
ttlMs;
|
|
35
36
|
maxSize;
|
|
36
37
|
cleanupInterval;
|
|
@@ -88,7 +89,7 @@ var TTLCache = class {
|
|
|
88
89
|
const entry = this.cache.get(key);
|
|
89
90
|
if (!entry) return void 0;
|
|
90
91
|
const now = Date.now();
|
|
91
|
-
if (now
|
|
92
|
+
if (now >= entry.expiresAt) {
|
|
92
93
|
this.cache.delete(key);
|
|
93
94
|
return void 0;
|
|
94
95
|
}
|
|
@@ -100,17 +101,31 @@ var TTLCache = class {
|
|
|
100
101
|
/**
|
|
101
102
|
* Retrieves or computes a value if it's not in the cache or has expired.
|
|
102
103
|
*
|
|
104
|
+
* Concurrent calls for the same key share the same producer promise,
|
|
105
|
+
* preventing duplicate computations while the value is being generated.
|
|
106
|
+
*
|
|
103
107
|
* @param key - The key to retrieve
|
|
104
108
|
* @param producer - Function to generate the value if not cached
|
|
105
109
|
* @param ttlMs - Optional custom TTL for the computed value
|
|
106
110
|
* @returns The cached or computed value
|
|
107
111
|
*/
|
|
108
112
|
async getOrCompute(key, producer, ttlMs) {
|
|
109
|
-
const
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
const cached = this.get(key);
|
|
114
|
+
if (cached !== void 0) {
|
|
115
|
+
return cached;
|
|
116
|
+
}
|
|
117
|
+
const pending = this.pending.get(key);
|
|
118
|
+
if (pending) {
|
|
119
|
+
return pending;
|
|
120
|
+
}
|
|
121
|
+
const promise = Promise.resolve().then(producer).then((value) => {
|
|
122
|
+
this.setWithTTL(key, value, ttlMs ?? this.ttlMs);
|
|
123
|
+
return value;
|
|
124
|
+
}).finally(() => {
|
|
125
|
+
this.pending.delete(key);
|
|
126
|
+
});
|
|
127
|
+
this.pending.set(key, promise);
|
|
128
|
+
return promise;
|
|
114
129
|
}
|
|
115
130
|
/**
|
|
116
131
|
* Checks if the key exists and hasn't expired.
|
|
@@ -172,7 +187,7 @@ var TTLCache = class {
|
|
|
172
187
|
let removed = 0;
|
|
173
188
|
const now = Date.now();
|
|
174
189
|
for (const [key, entry] of this.cache.entries()) {
|
|
175
|
-
if (now
|
|
190
|
+
if (now >= entry.expiresAt) {
|
|
176
191
|
this.cache.delete(key);
|
|
177
192
|
removed++;
|
|
178
193
|
}
|
|
@@ -186,7 +201,7 @@ var TTLCache = class {
|
|
|
186
201
|
*/
|
|
187
202
|
*entries() {
|
|
188
203
|
for (const [key, entry] of this.cache.entries()) {
|
|
189
|
-
if (Date.now()
|
|
204
|
+
if (Date.now() < entry.expiresAt) {
|
|
190
205
|
yield [
|
|
191
206
|
key,
|
|
192
207
|
entry.value
|
|
@@ -201,7 +216,7 @@ var TTLCache = class {
|
|
|
201
216
|
*/
|
|
202
217
|
*keys() {
|
|
203
218
|
for (const [key, entry] of this.cache.entries()) {
|
|
204
|
-
if (Date.now()
|
|
219
|
+
if (Date.now() < entry.expiresAt) {
|
|
205
220
|
yield key;
|
|
206
221
|
}
|
|
207
222
|
}
|
|
@@ -213,7 +228,7 @@ var TTLCache = class {
|
|
|
213
228
|
*/
|
|
214
229
|
*values() {
|
|
215
230
|
for (const entry of this.cache.values()) {
|
|
216
|
-
if (Date.now()
|
|
231
|
+
if (Date.now() < entry.expiresAt) {
|
|
217
232
|
yield entry.value;
|
|
218
233
|
}
|
|
219
234
|
}
|
|
@@ -229,12 +244,14 @@ var TTLCache = class {
|
|
|
229
244
|
const entry = this.cache.get(key);
|
|
230
245
|
if (!entry) return false;
|
|
231
246
|
const now = Date.now();
|
|
232
|
-
if (now
|
|
247
|
+
if (now >= entry.expiresAt) {
|
|
233
248
|
this.cache.delete(key);
|
|
234
249
|
return false;
|
|
235
250
|
}
|
|
236
251
|
entry.expiresAt = now + (ttlMs ?? this.ttlMs);
|
|
237
252
|
entry.lastAccessed = now;
|
|
253
|
+
this.cache.delete(key);
|
|
254
|
+
this.cache.set(key, entry);
|
|
238
255
|
return true;
|
|
239
256
|
}
|
|
240
257
|
/**
|
|
@@ -247,7 +264,7 @@ var TTLCache = class {
|
|
|
247
264
|
let expired = 0;
|
|
248
265
|
let valid = 0;
|
|
249
266
|
for (const entry of this.cache.values()) {
|
|
250
|
-
if (now
|
|
267
|
+
if (now >= entry.expiresAt) {
|
|
251
268
|
expired++;
|
|
252
269
|
} else {
|
|
253
270
|
valid++;
|
|
@@ -275,14 +292,17 @@ var TTLCache = class {
|
|
|
275
292
|
*/
|
|
276
293
|
evictLRU() {
|
|
277
294
|
const now = Date.now();
|
|
278
|
-
for (const [key, entry] of
|
|
279
|
-
if (now
|
|
295
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
296
|
+
if (now >= entry.expiresAt) {
|
|
280
297
|
this.cache.delete(key);
|
|
281
298
|
}
|
|
282
299
|
}
|
|
283
300
|
while (this.maxSize && this.cache.size > this.maxSize) {
|
|
284
|
-
const
|
|
285
|
-
|
|
301
|
+
const next = this.cache.keys().next();
|
|
302
|
+
if (next.done) {
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
this.cache.delete(next.value);
|
|
286
306
|
}
|
|
287
307
|
}
|
|
288
308
|
};
|
package/config/index.cjs
CHANGED
|
@@ -94,11 +94,6 @@ var defaultServerConfig = {
|
|
|
94
94
|
exposeHeader: env.Env.getBoolean("SERVER_REQUEST_ID_EXPOSE_HEADER", true),
|
|
95
95
|
generator: /* @__PURE__ */ __name(() => id.uuid(), "generator")
|
|
96
96
|
},
|
|
97
|
-
metrics: {
|
|
98
|
-
enable: env.Env.getBoolean("SERVER_METRICS_ENABLE", false),
|
|
99
|
-
path: env.Env.get("SERVER_METRICS_PATH", "/metrics"),
|
|
100
|
-
withGlobalPrefix: env.Env.getBoolean("SERVER_METRICS_WITH_GLOBAL_PREFIX", false)
|
|
101
|
-
},
|
|
102
97
|
serviceVersion: {
|
|
103
98
|
enable: env.Env.getBoolean("SERVER_SERVICE_VERSION_ENABLE", false),
|
|
104
99
|
headerName: env.Env.get("SERVER_SERVICE_VERSION_HEADER_NAME", "x-service-version"),
|
package/config/index.mjs
CHANGED
|
@@ -92,11 +92,6 @@ var defaultServerConfig = {
|
|
|
92
92
|
exposeHeader: Env.getBoolean("SERVER_REQUEST_ID_EXPOSE_HEADER", true),
|
|
93
93
|
generator: /* @__PURE__ */ __name(() => uuid(), "generator")
|
|
94
94
|
},
|
|
95
|
-
metrics: {
|
|
96
|
-
enable: Env.getBoolean("SERVER_METRICS_ENABLE", false),
|
|
97
|
-
path: Env.get("SERVER_METRICS_PATH", "/metrics"),
|
|
98
|
-
withGlobalPrefix: Env.getBoolean("SERVER_METRICS_WITH_GLOBAL_PREFIX", false)
|
|
99
|
-
},
|
|
100
95
|
serviceVersion: {
|
|
101
96
|
enable: Env.getBoolean("SERVER_SERVICE_VERSION_ENABLE", false),
|
|
102
97
|
headerName: Env.get("SERVER_SERVICE_VERSION_HEADER_NAME", "x-service-version"),
|
package/crypto/index.cjs
CHANGED
|
@@ -457,8 +457,16 @@ function generateNonce(byteLength = 16, encoding = "hex") {
|
|
|
457
457
|
}
|
|
458
458
|
__name(generateNonce, "generateNonce");
|
|
459
459
|
function secureRandomInt(min, max) {
|
|
460
|
-
if (min
|
|
460
|
+
if (!Number.isSafeInteger(min) || !Number.isSafeInteger(max)) {
|
|
461
|
+
throw new TypeError("min and max must be safe integers");
|
|
462
|
+
}
|
|
463
|
+
if (min > max) {
|
|
464
|
+
throw new RangeError("min must be less than or equal to max");
|
|
465
|
+
}
|
|
461
466
|
const range = max - min + 1;
|
|
467
|
+
if (!Number.isSafeInteger(range) || range <= 0) {
|
|
468
|
+
throw new RangeError("Range is too large");
|
|
469
|
+
}
|
|
462
470
|
const bytesNeeded = Math.ceil(Math.log2(range) / 8);
|
|
463
471
|
const maxValid = Math.floor(256 ** bytesNeeded / range) * range;
|
|
464
472
|
let randomValue;
|
package/crypto/index.mjs
CHANGED
|
@@ -455,8 +455,16 @@ function generateNonce(byteLength = 16, encoding = "hex") {
|
|
|
455
455
|
}
|
|
456
456
|
__name(generateNonce, "generateNonce");
|
|
457
457
|
function secureRandomInt(min, max) {
|
|
458
|
-
if (min
|
|
458
|
+
if (!Number.isSafeInteger(min) || !Number.isSafeInteger(max)) {
|
|
459
|
+
throw new TypeError("min and max must be safe integers");
|
|
460
|
+
}
|
|
461
|
+
if (min > max) {
|
|
462
|
+
throw new RangeError("min must be less than or equal to max");
|
|
463
|
+
}
|
|
459
464
|
const range = max - min + 1;
|
|
465
|
+
if (!Number.isSafeInteger(range) || range <= 0) {
|
|
466
|
+
throw new RangeError("Range is too large");
|
|
467
|
+
}
|
|
460
468
|
const bytesNeeded = Math.ceil(Math.log2(range) / 8);
|
|
461
469
|
const maxValid = Math.floor(256 ** bytesNeeded / range) * range;
|
|
462
470
|
let randomValue;
|
package/date/index.cjs
CHANGED
|
@@ -575,6 +575,278 @@ function getTimeZoneParts(date, timeZone) {
|
|
|
575
575
|
};
|
|
576
576
|
}
|
|
577
577
|
__name(getTimeZoneParts, "getTimeZoneParts");
|
|
578
|
+
var COUNTRY_CODES = [
|
|
579
|
+
"AD",
|
|
580
|
+
"AE",
|
|
581
|
+
"AF",
|
|
582
|
+
"AG",
|
|
583
|
+
"AI",
|
|
584
|
+
"AL",
|
|
585
|
+
"AM",
|
|
586
|
+
"AO",
|
|
587
|
+
"AQ",
|
|
588
|
+
"AR",
|
|
589
|
+
"AS",
|
|
590
|
+
"AT",
|
|
591
|
+
"AU",
|
|
592
|
+
"AW",
|
|
593
|
+
"AX",
|
|
594
|
+
"AZ",
|
|
595
|
+
"BA",
|
|
596
|
+
"BB",
|
|
597
|
+
"BD",
|
|
598
|
+
"BE",
|
|
599
|
+
"BF",
|
|
600
|
+
"BG",
|
|
601
|
+
"BH",
|
|
602
|
+
"BI",
|
|
603
|
+
"BJ",
|
|
604
|
+
"BL",
|
|
605
|
+
"BM",
|
|
606
|
+
"BN",
|
|
607
|
+
"BO",
|
|
608
|
+
"BQ",
|
|
609
|
+
"BR",
|
|
610
|
+
"BS",
|
|
611
|
+
"BT",
|
|
612
|
+
"BV",
|
|
613
|
+
"BW",
|
|
614
|
+
"BY",
|
|
615
|
+
"BZ",
|
|
616
|
+
"CA",
|
|
617
|
+
"CC",
|
|
618
|
+
"CD",
|
|
619
|
+
"CF",
|
|
620
|
+
"CG",
|
|
621
|
+
"CH",
|
|
622
|
+
"CI",
|
|
623
|
+
"CK",
|
|
624
|
+
"CL",
|
|
625
|
+
"CM",
|
|
626
|
+
"CN",
|
|
627
|
+
"CO",
|
|
628
|
+
"CR",
|
|
629
|
+
"CU",
|
|
630
|
+
"CV",
|
|
631
|
+
"CW",
|
|
632
|
+
"CX",
|
|
633
|
+
"CY",
|
|
634
|
+
"CZ",
|
|
635
|
+
"DE",
|
|
636
|
+
"DJ",
|
|
637
|
+
"DK",
|
|
638
|
+
"DM",
|
|
639
|
+
"DO",
|
|
640
|
+
"DZ",
|
|
641
|
+
"EC",
|
|
642
|
+
"EE",
|
|
643
|
+
"EG",
|
|
644
|
+
"EH",
|
|
645
|
+
"ER",
|
|
646
|
+
"ES",
|
|
647
|
+
"ET",
|
|
648
|
+
"FI",
|
|
649
|
+
"FJ",
|
|
650
|
+
"FK",
|
|
651
|
+
"FM",
|
|
652
|
+
"FO",
|
|
653
|
+
"FR",
|
|
654
|
+
"GA",
|
|
655
|
+
"GB",
|
|
656
|
+
"GD",
|
|
657
|
+
"GE",
|
|
658
|
+
"GF",
|
|
659
|
+
"GG",
|
|
660
|
+
"GH",
|
|
661
|
+
"GI",
|
|
662
|
+
"GL",
|
|
663
|
+
"GM",
|
|
664
|
+
"GN",
|
|
665
|
+
"GP",
|
|
666
|
+
"GQ",
|
|
667
|
+
"GR",
|
|
668
|
+
"GS",
|
|
669
|
+
"GT",
|
|
670
|
+
"GU",
|
|
671
|
+
"GW",
|
|
672
|
+
"GY",
|
|
673
|
+
"HK",
|
|
674
|
+
"HM",
|
|
675
|
+
"HN",
|
|
676
|
+
"HR",
|
|
677
|
+
"HT",
|
|
678
|
+
"HU",
|
|
679
|
+
"ID",
|
|
680
|
+
"IE",
|
|
681
|
+
"IL",
|
|
682
|
+
"IM",
|
|
683
|
+
"IN",
|
|
684
|
+
"IO",
|
|
685
|
+
"IQ",
|
|
686
|
+
"IR",
|
|
687
|
+
"IS",
|
|
688
|
+
"IT",
|
|
689
|
+
"JE",
|
|
690
|
+
"JM",
|
|
691
|
+
"JO",
|
|
692
|
+
"JP",
|
|
693
|
+
"KE",
|
|
694
|
+
"KG",
|
|
695
|
+
"KH",
|
|
696
|
+
"KI",
|
|
697
|
+
"KM",
|
|
698
|
+
"KN",
|
|
699
|
+
"KP",
|
|
700
|
+
"KR",
|
|
701
|
+
"KW",
|
|
702
|
+
"KY",
|
|
703
|
+
"KZ",
|
|
704
|
+
"LA",
|
|
705
|
+
"LB",
|
|
706
|
+
"LC",
|
|
707
|
+
"LI",
|
|
708
|
+
"LK",
|
|
709
|
+
"LR",
|
|
710
|
+
"LS",
|
|
711
|
+
"LT",
|
|
712
|
+
"LU",
|
|
713
|
+
"LV",
|
|
714
|
+
"LY",
|
|
715
|
+
"MA",
|
|
716
|
+
"MC",
|
|
717
|
+
"MD",
|
|
718
|
+
"ME",
|
|
719
|
+
"MF",
|
|
720
|
+
"MG",
|
|
721
|
+
"MH",
|
|
722
|
+
"MK",
|
|
723
|
+
"ML",
|
|
724
|
+
"MM",
|
|
725
|
+
"MN",
|
|
726
|
+
"MO",
|
|
727
|
+
"MP",
|
|
728
|
+
"MQ",
|
|
729
|
+
"MR",
|
|
730
|
+
"MS",
|
|
731
|
+
"MT",
|
|
732
|
+
"MU",
|
|
733
|
+
"MV",
|
|
734
|
+
"MW",
|
|
735
|
+
"MX",
|
|
736
|
+
"MY",
|
|
737
|
+
"MZ",
|
|
738
|
+
"NA",
|
|
739
|
+
"NC",
|
|
740
|
+
"NE",
|
|
741
|
+
"NF",
|
|
742
|
+
"NG",
|
|
743
|
+
"NI",
|
|
744
|
+
"NL",
|
|
745
|
+
"NO",
|
|
746
|
+
"NP",
|
|
747
|
+
"NR",
|
|
748
|
+
"NU",
|
|
749
|
+
"NZ",
|
|
750
|
+
"OM",
|
|
751
|
+
"PA",
|
|
752
|
+
"PE",
|
|
753
|
+
"PF",
|
|
754
|
+
"PG",
|
|
755
|
+
"PH",
|
|
756
|
+
"PK",
|
|
757
|
+
"PL",
|
|
758
|
+
"PM",
|
|
759
|
+
"PN",
|
|
760
|
+
"PR",
|
|
761
|
+
"PS",
|
|
762
|
+
"PT",
|
|
763
|
+
"PW",
|
|
764
|
+
"PY",
|
|
765
|
+
"QA",
|
|
766
|
+
"RE",
|
|
767
|
+
"RO",
|
|
768
|
+
"RS",
|
|
769
|
+
"RU",
|
|
770
|
+
"RW",
|
|
771
|
+
"SA",
|
|
772
|
+
"SB",
|
|
773
|
+
"SC",
|
|
774
|
+
"SD",
|
|
775
|
+
"SE",
|
|
776
|
+
"SG",
|
|
777
|
+
"SH",
|
|
778
|
+
"SI",
|
|
779
|
+
"SJ",
|
|
780
|
+
"SK",
|
|
781
|
+
"SL",
|
|
782
|
+
"SM",
|
|
783
|
+
"SN",
|
|
784
|
+
"SO",
|
|
785
|
+
"SR",
|
|
786
|
+
"SS",
|
|
787
|
+
"ST",
|
|
788
|
+
"SV",
|
|
789
|
+
"SX",
|
|
790
|
+
"SY",
|
|
791
|
+
"SZ",
|
|
792
|
+
"TC",
|
|
793
|
+
"TD",
|
|
794
|
+
"TF",
|
|
795
|
+
"TG",
|
|
796
|
+
"TH",
|
|
797
|
+
"TJ",
|
|
798
|
+
"TK",
|
|
799
|
+
"TL",
|
|
800
|
+
"TM",
|
|
801
|
+
"TN",
|
|
802
|
+
"TO",
|
|
803
|
+
"TR",
|
|
804
|
+
"TT",
|
|
805
|
+
"TV",
|
|
806
|
+
"TW",
|
|
807
|
+
"TZ",
|
|
808
|
+
"UA",
|
|
809
|
+
"UG",
|
|
810
|
+
"UM",
|
|
811
|
+
"US",
|
|
812
|
+
"UY",
|
|
813
|
+
"UZ",
|
|
814
|
+
"VA",
|
|
815
|
+
"VC",
|
|
816
|
+
"VE",
|
|
817
|
+
"VG",
|
|
818
|
+
"VI",
|
|
819
|
+
"VN",
|
|
820
|
+
"VU",
|
|
821
|
+
"WF",
|
|
822
|
+
"WS",
|
|
823
|
+
"YE",
|
|
824
|
+
"YT",
|
|
825
|
+
"ZA",
|
|
826
|
+
"ZM",
|
|
827
|
+
"ZW"
|
|
828
|
+
];
|
|
829
|
+
function getCountries(locale = "en") {
|
|
830
|
+
const regionNames = new Intl.DisplayNames([
|
|
831
|
+
locale
|
|
832
|
+
], {
|
|
833
|
+
type: "region"
|
|
834
|
+
});
|
|
835
|
+
return COUNTRY_CODES.map((code) => ({
|
|
836
|
+
code,
|
|
837
|
+
name: regionNames.of(code)
|
|
838
|
+
}));
|
|
839
|
+
}
|
|
840
|
+
__name(getCountries, "getCountries");
|
|
841
|
+
var SUPPORTED_TIMEZONE_NAMES = Intl.supportedValuesOf("timeZone");
|
|
842
|
+
var TIMEZONE_NAMES = SUPPORTED_TIMEZONE_NAMES.includes("UTC") ? SUPPORTED_TIMEZONE_NAMES : [
|
|
843
|
+
...SUPPORTED_TIMEZONE_NAMES,
|
|
844
|
+
"UTC"
|
|
845
|
+
].sort((a, b) => a.localeCompare(b));
|
|
846
|
+
function getTimezones() {
|
|
847
|
+
return TIMEZONE_NAMES;
|
|
848
|
+
}
|
|
849
|
+
__name(getTimezones, "getTimezones");
|
|
578
850
|
|
|
579
851
|
// src/date/date.builder.ts
|
|
580
852
|
var DateBuilder = class _DateBuilder {
|
|
@@ -1179,7 +1451,9 @@ var DateBuilder = class _DateBuilder {
|
|
|
1179
1451
|
}
|
|
1180
1452
|
};
|
|
1181
1453
|
|
|
1454
|
+
exports.COUNTRY_CODES = COUNTRY_CODES;
|
|
1182
1455
|
exports.DateBuilder = DateBuilder;
|
|
1456
|
+
exports.TIMEZONE_NAMES = TIMEZONE_NAMES;
|
|
1183
1457
|
exports.addDays = addDays;
|
|
1184
1458
|
exports.addMonths = addMonths;
|
|
1185
1459
|
exports.addToDate = addToDate;
|
|
@@ -1192,9 +1466,11 @@ exports.formatDate = formatDate;
|
|
|
1192
1466
|
exports.formatDateInTimeZone = formatDateInTimeZone;
|
|
1193
1467
|
exports.formatDuration = formatDuration;
|
|
1194
1468
|
exports.formatRelativeTime = formatRelativeTime;
|
|
1469
|
+
exports.getCountries = getCountries;
|
|
1195
1470
|
exports.getDateFromDuration = getDateFromDuration;
|
|
1196
1471
|
exports.getTimezoneAbbreviation = getTimezoneAbbreviation;
|
|
1197
1472
|
exports.getTimezoneOffset = getTimezoneOffset;
|
|
1473
|
+
exports.getTimezones = getTimezones;
|
|
1198
1474
|
exports.isBetween = isBetween;
|
|
1199
1475
|
exports.isDST = isDST;
|
|
1200
1476
|
exports.isFuture = isFuture;
|