@etsoo/shared 1.2.60 → 1.2.62

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.
@@ -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?.name).toBe("zh-Hans");
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?.name).toBe("zh-Hans");
239
+ expect(culture2.name).toBe("zh-Hans");
240
240
 
241
241
  const [culture3] = DomUtils.getCulture(cultures, "zh-Hans-HK");
242
- expect(culture3?.name).toBe("zh-Hans");
242
+ expect(culture3.name).toBe("zh-Hans");
243
243
 
244
244
  const [culture4] = DomUtils.getCulture(cultures, "zh-SG");
245
- expect(culture4?.name).toBe("zh-Hans");
245
+ expect(culture4.name).toBe("zh-Hans");
246
246
 
247
247
  const [culture5] = DomUtils.getCulture(cultures, "en-GB");
248
- expect(culture5?.name).toBe("en");
248
+ expect(culture5.name).toBe("en");
249
249
 
250
250
  const [culture6, match6] = DomUtils.getCulture(cultures, "fr-CA");
251
- expect(culture6?.name).toBe("zh-Hans");
251
+ expect(culture6.name).toBe("zh-Hans");
252
252
  expect(match6).toBe(DomUtils.CultureMatch.Default);
253
253
  });
254
254
 
@@ -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> | undefined, CultureMatch];
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
@@ -364,7 +364,7 @@ var DomUtils;
364
364
  */
365
365
  DomUtils.getCulture = (items, culture) => {
366
366
  if (items.length === 0) {
367
- return [undefined, CultureMatch.Exact];
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);
@@ -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> | undefined, CultureMatch];
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
@@ -361,7 +361,7 @@ export var DomUtils;
361
361
  */
362
362
  DomUtils.getCulture = (items, culture) => {
363
363
  if (items.length === 0) {
364
- return [undefined, CultureMatch.Exact];
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.2.60",
3
+ "version": "1.2.62",
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.4"
43
+ "vitest": "^3.0.7"
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> | undefined, CultureMatch] => {
472
+ ): [DataTypes.CultureDefinition<T>, CultureMatch] => {
473
473
  if (items.length === 0) {
474
- return [undefined, CultureMatch.Exact];
474
+ throw new Error("Culture items cannot be empty");
475
475
  }
476
476
 
477
477
  // Exact match