@etsoo/shared 1.2.59 → 1.2.61
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/__tests__/DomUtils.ts +6 -6
- package/lib/cjs/DomUtils.d.ts +1 -1
- package/lib/cjs/DomUtils.js +1 -1
- package/lib/cjs/Utils.d.ts +2 -1
- package/lib/cjs/Utils.js +4 -1
- package/lib/mjs/DomUtils.d.ts +1 -1
- package/lib/mjs/DomUtils.js +1 -1
- package/lib/mjs/Utils.d.ts +2 -1
- package/lib/mjs/Utils.js +4 -1
- package/package.json +2 -2
- package/src/DomUtils.ts +2 -2
- package/src/Utils.ts +5 -1
package/__tests__/DomUtils.ts
CHANGED
|
@@ -232,23 +232,23 @@ test("Tests for getCulture", () => {
|
|
|
232
232
|
];
|
|
233
233
|
|
|
234
234
|
const [culture1, match1] = DomUtils.getCulture(cultures, "zh-CN");
|
|
235
|
-
expect(culture1
|
|
235
|
+
expect(culture1.name).toBe("zh-Hans");
|
|
236
236
|
expect(match1).toBe(DomUtils.CultureMatch.Compatible);
|
|
237
237
|
|
|
238
238
|
const [culture2] = DomUtils.getCulture(cultures, "zh-Hans-CN");
|
|
239
|
-
expect(culture2
|
|
239
|
+
expect(culture2.name).toBe("zh-Hans");
|
|
240
240
|
|
|
241
241
|
const [culture3] = DomUtils.getCulture(cultures, "zh-Hans-HK");
|
|
242
|
-
expect(culture3
|
|
242
|
+
expect(culture3.name).toBe("zh-Hans");
|
|
243
243
|
|
|
244
244
|
const [culture4] = DomUtils.getCulture(cultures, "zh-SG");
|
|
245
|
-
expect(culture4
|
|
245
|
+
expect(culture4.name).toBe("zh-Hans");
|
|
246
246
|
|
|
247
247
|
const [culture5] = DomUtils.getCulture(cultures, "en-GB");
|
|
248
|
-
expect(culture5
|
|
248
|
+
expect(culture5.name).toBe("en");
|
|
249
249
|
|
|
250
250
|
const [culture6, match6] = DomUtils.getCulture(cultures, "fr-CA");
|
|
251
|
-
expect(culture6
|
|
251
|
+
expect(culture6.name).toBe("zh-Hans");
|
|
252
252
|
expect(match6).toBe(DomUtils.CultureMatch.Default);
|
|
253
253
|
});
|
|
254
254
|
|
package/lib/cjs/DomUtils.d.ts
CHANGED
|
@@ -137,7 +137,7 @@ export declare namespace DomUtils {
|
|
|
137
137
|
* @param items Available cultures
|
|
138
138
|
* @param culture Detected culture
|
|
139
139
|
*/
|
|
140
|
-
const getCulture: <T extends DataTypes.StringRecord>(items: DataTypes.CultureDefinition<T>[], culture: string) => [DataTypes.CultureDefinition<T
|
|
140
|
+
const getCulture: <T extends DataTypes.StringRecord>(items: DataTypes.CultureDefinition<T>[], culture: string) => [DataTypes.CultureDefinition<T>, CultureMatch];
|
|
141
141
|
/**
|
|
142
142
|
* Get input value depending on its type
|
|
143
143
|
* @param input HTML input
|
package/lib/cjs/DomUtils.js
CHANGED
|
@@ -364,7 +364,7 @@ var DomUtils;
|
|
|
364
364
|
*/
|
|
365
365
|
DomUtils.getCulture = (items, culture) => {
|
|
366
366
|
if (items.length === 0) {
|
|
367
|
-
|
|
367
|
+
throw new Error("Culture items cannot be empty");
|
|
368
368
|
}
|
|
369
369
|
// Exact match
|
|
370
370
|
const exactMatch = items.find((item) => item.name === culture);
|
package/lib/cjs/Utils.d.ts
CHANGED
|
@@ -176,9 +176,10 @@ export declare namespace Utils {
|
|
|
176
176
|
export const getResult: <R, T = R | DataTypes.Func<R>>(input: T, ...args: T extends DataTypes.Func<R> ? Parameters<typeof input> : never | []) => T extends DataTypes.Func<R> ? ReturnType<T> : T;
|
|
177
177
|
/**
|
|
178
178
|
* Get time zone
|
|
179
|
+
* @param tz Default timezone, default is UTC
|
|
179
180
|
* @returns Timezone
|
|
180
181
|
*/
|
|
181
|
-
export const getTimeZone: () => string
|
|
182
|
+
export const getTimeZone: (tz?: string) => string;
|
|
182
183
|
/**
|
|
183
184
|
* Is digits string
|
|
184
185
|
* @param input Input string
|
package/lib/cjs/Utils.js
CHANGED
|
@@ -343,12 +343,15 @@ var Utils;
|
|
|
343
343
|
};
|
|
344
344
|
/**
|
|
345
345
|
* Get time zone
|
|
346
|
+
* @param tz Default timezone, default is UTC
|
|
346
347
|
* @returns Timezone
|
|
347
348
|
*/
|
|
348
|
-
Utils.getTimeZone = () => {
|
|
349
|
+
Utils.getTimeZone = (tz) => {
|
|
349
350
|
// If Intl supported
|
|
350
351
|
if (typeof Intl === "object" && typeof Intl.DateTimeFormat === "function")
|
|
351
352
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
353
|
+
// Default timezone
|
|
354
|
+
return tz ?? "UTC";
|
|
352
355
|
};
|
|
353
356
|
/**
|
|
354
357
|
* Is digits string
|
package/lib/mjs/DomUtils.d.ts
CHANGED
|
@@ -137,7 +137,7 @@ export declare namespace DomUtils {
|
|
|
137
137
|
* @param items Available cultures
|
|
138
138
|
* @param culture Detected culture
|
|
139
139
|
*/
|
|
140
|
-
const getCulture: <T extends DataTypes.StringRecord>(items: DataTypes.CultureDefinition<T>[], culture: string) => [DataTypes.CultureDefinition<T
|
|
140
|
+
const getCulture: <T extends DataTypes.StringRecord>(items: DataTypes.CultureDefinition<T>[], culture: string) => [DataTypes.CultureDefinition<T>, CultureMatch];
|
|
141
141
|
/**
|
|
142
142
|
* Get input value depending on its type
|
|
143
143
|
* @param input HTML input
|
package/lib/mjs/DomUtils.js
CHANGED
|
@@ -361,7 +361,7 @@ export var DomUtils;
|
|
|
361
361
|
*/
|
|
362
362
|
DomUtils.getCulture = (items, culture) => {
|
|
363
363
|
if (items.length === 0) {
|
|
364
|
-
|
|
364
|
+
throw new Error("Culture items cannot be empty");
|
|
365
365
|
}
|
|
366
366
|
// Exact match
|
|
367
367
|
const exactMatch = items.find((item) => item.name === culture);
|
package/lib/mjs/Utils.d.ts
CHANGED
|
@@ -176,9 +176,10 @@ export declare namespace Utils {
|
|
|
176
176
|
export const getResult: <R, T = R | DataTypes.Func<R>>(input: T, ...args: T extends DataTypes.Func<R> ? Parameters<typeof input> : never | []) => T extends DataTypes.Func<R> ? ReturnType<T> : T;
|
|
177
177
|
/**
|
|
178
178
|
* Get time zone
|
|
179
|
+
* @param tz Default timezone, default is UTC
|
|
179
180
|
* @returns Timezone
|
|
180
181
|
*/
|
|
181
|
-
export const getTimeZone: () => string
|
|
182
|
+
export const getTimeZone: (tz?: string) => string;
|
|
182
183
|
/**
|
|
183
184
|
* Is digits string
|
|
184
185
|
* @param input Input string
|
package/lib/mjs/Utils.js
CHANGED
|
@@ -337,12 +337,15 @@ export var Utils;
|
|
|
337
337
|
};
|
|
338
338
|
/**
|
|
339
339
|
* Get time zone
|
|
340
|
+
* @param tz Default timezone, default is UTC
|
|
340
341
|
* @returns Timezone
|
|
341
342
|
*/
|
|
342
|
-
Utils.getTimeZone = () => {
|
|
343
|
+
Utils.getTimeZone = (tz) => {
|
|
343
344
|
// If Intl supported
|
|
344
345
|
if (typeof Intl === "object" && typeof Intl.DateTimeFormat === "function")
|
|
345
346
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
347
|
+
// Default timezone
|
|
348
|
+
return tz ?? "UTC";
|
|
346
349
|
};
|
|
347
350
|
/**
|
|
348
351
|
* Is digits string
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/shared",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.61",
|
|
4
4
|
"description": "TypeScript shared utilities and functions",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@vitejs/plugin-react": "^4.3.4",
|
|
41
41
|
"jsdom": "^26.0.0",
|
|
42
42
|
"typescript": "^5.7.3",
|
|
43
|
-
"vitest": "^3.0.
|
|
43
|
+
"vitest": "^3.0.5"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"lodash.isequal": "^4.5.0"
|
package/src/DomUtils.ts
CHANGED
|
@@ -469,9 +469,9 @@ export namespace DomUtils {
|
|
|
469
469
|
export const getCulture = <T extends DataTypes.StringRecord>(
|
|
470
470
|
items: DataTypes.CultureDefinition<T>[],
|
|
471
471
|
culture: string
|
|
472
|
-
): [DataTypes.CultureDefinition<T
|
|
472
|
+
): [DataTypes.CultureDefinition<T>, CultureMatch] => {
|
|
473
473
|
if (items.length === 0) {
|
|
474
|
-
|
|
474
|
+
throw new Error("Culture items cannot be empty");
|
|
475
475
|
}
|
|
476
476
|
|
|
477
477
|
// Exact match
|
package/src/Utils.ts
CHANGED
|
@@ -504,12 +504,16 @@ export namespace Utils {
|
|
|
504
504
|
|
|
505
505
|
/**
|
|
506
506
|
* Get time zone
|
|
507
|
+
* @param tz Default timezone, default is UTC
|
|
507
508
|
* @returns Timezone
|
|
508
509
|
*/
|
|
509
|
-
export const getTimeZone = () => {
|
|
510
|
+
export const getTimeZone = (tz?: string) => {
|
|
510
511
|
// If Intl supported
|
|
511
512
|
if (typeof Intl === "object" && typeof Intl.DateTimeFormat === "function")
|
|
512
513
|
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
514
|
+
|
|
515
|
+
// Default timezone
|
|
516
|
+
return tz ?? "UTC";
|
|
513
517
|
};
|
|
514
518
|
|
|
515
519
|
/**
|