@trackunit/shared-utils 1.15.57 → 1.15.59

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/index.cjs.js CHANGED
@@ -426,6 +426,28 @@ searchTerm) => {
426
426
  .every(term => filterableProps(asset).some(value => value.toLowerCase().includes(term.toLowerCase()))));
427
427
  };
428
428
 
429
+ /**
430
+ * Resolve a country code to its localized, user-friendly country name.
431
+ *
432
+ * @param countryCode - ISO 3166-1 alpha-2 country code, e.g. "DK". Matching is case-insensitive: the code is normalized to upper-case before lookup.
433
+ * @param languages - Preferred display languages, typically `i18n.languages` (may be undefined before i18next is ready).
434
+ * @returns {string} The localized country name, or the original code when it cannot be resolved.
435
+ */
436
+ const getCountryName = (countryCode, languages) => {
437
+ if (!countryCode) {
438
+ return countryCode;
439
+ }
440
+ try {
441
+ const locales = languages && languages.length > 0 ? [...languages] : undefined;
442
+ const regionNames = new Intl.DisplayNames(locales, { type: "region", fallback: "none" });
443
+ return regionNames.of(countryCode.toUpperCase()) ?? countryCode;
444
+ }
445
+ catch {
446
+ // `of` throws a RangeError for structurally invalid codes — keep the raw value.
447
+ return countryCode;
448
+ }
449
+ };
450
+
429
451
  /**
430
452
  * Group an array of items by a key.
431
453
  *
@@ -1603,6 +1625,7 @@ exports.formatSiDistance = formatSiDistance;
1603
1625
  exports.formatUsCustomaryDistance = formatUsCustomaryDistance;
1604
1626
  exports.fuzzySearch = fuzzySearch;
1605
1627
  exports.getAllColors = getAllColors;
1628
+ exports.getCountryName = getCountryName;
1606
1629
  exports.getDifferenceBetweenDates = getDifferenceBetweenDates;
1607
1630
  exports.getEndOfDay = getEndOfDay;
1608
1631
  exports.getFirstLevelObjectPropertyDifferences = getFirstLevelObjectPropertyDifferences;
package/index.esm.js CHANGED
@@ -424,6 +424,28 @@ searchTerm) => {
424
424
  .every(term => filterableProps(asset).some(value => value.toLowerCase().includes(term.toLowerCase()))));
425
425
  };
426
426
 
427
+ /**
428
+ * Resolve a country code to its localized, user-friendly country name.
429
+ *
430
+ * @param countryCode - ISO 3166-1 alpha-2 country code, e.g. "DK". Matching is case-insensitive: the code is normalized to upper-case before lookup.
431
+ * @param languages - Preferred display languages, typically `i18n.languages` (may be undefined before i18next is ready).
432
+ * @returns {string} The localized country name, or the original code when it cannot be resolved.
433
+ */
434
+ const getCountryName = (countryCode, languages) => {
435
+ if (!countryCode) {
436
+ return countryCode;
437
+ }
438
+ try {
439
+ const locales = languages && languages.length > 0 ? [...languages] : undefined;
440
+ const regionNames = new Intl.DisplayNames(locales, { type: "region", fallback: "none" });
441
+ return regionNames.of(countryCode.toUpperCase()) ?? countryCode;
442
+ }
443
+ catch {
444
+ // `of` throws a RangeError for structurally invalid codes — keep the raw value.
445
+ return countryCode;
446
+ }
447
+ };
448
+
427
449
  /**
428
450
  * Group an array of items by a key.
429
451
  *
@@ -1567,4 +1589,4 @@ const formatUsCustomaryDistance = (value) => {
1567
1589
  }
1568
1590
  };
1569
1591
 
1570
- export { DateTimeFormat, HoursAndMinutesFormat, UnitsOfMeasurementSI, UnitsOfMeasurementUSCustomary, VISIBLE_ONLY_COLUMN_VISIBILITY_KEY, align, alphabeticallySort, arrayLengthCompare, arrayNotEmpty, booleanCompare, calculateImageScaleRatio, capitalize, colorsFromStyleDeclaration, convertBlobToBase64, convertMetersToKilometers, convertMetersToYards, convertYardsToMeters, convertYardsToMiles, dateCompare, deleteUndefinedKeys, difference, doNothing, enumFromValue, enumFromValueTypesafe, enumOrUndefinedFromValue, exhaustiveCheck, fetchImageAsBase64, filterByMultiple, formatAddress, formatCoordinates, formatSiDistance, formatUsCustomaryDistance, fuzzySearch, getAllColors, getDifferenceBetweenDates, getEndOfDay, getFirstLevelObjectPropertyDifferences, getISOStringFromDate, getLoremIpsum, getMimeTypeFromDataURL, getResizedDimensions, getStartOfDay, groupBy, groupTinyDataToOthers, hourIntervals, intersection, isArrayEqual, isSortByProperty, isSorted, isUUID, isValidImage, loadSVGDimensions, nonNullable, numberCompare, numberCompareUnknownAfterHighest, objNotEmpty, objectEntries, objectFromEntries, objectKeys, objectValues, parseTailwindArbitraryValue, pick, preload, removeLeftPadding, removeProperties, removeProperty, replaceNullableNumbersWithZero, resizeBlob, resizeImage, rgb2hex, size, stringCompare, stringCompareFromKey, stringNaturalCompare, stripHiddenCharacters, svgToPNG, titleCase, toID, toIDs, toPNG, toUUID, trimIds, trimPath, truthy, unionArraysByKey, uuidv3, uuidv4, uuidv5 };
1592
+ export { DateTimeFormat, HoursAndMinutesFormat, UnitsOfMeasurementSI, UnitsOfMeasurementUSCustomary, VISIBLE_ONLY_COLUMN_VISIBILITY_KEY, align, alphabeticallySort, arrayLengthCompare, arrayNotEmpty, booleanCompare, calculateImageScaleRatio, capitalize, colorsFromStyleDeclaration, convertBlobToBase64, convertMetersToKilometers, convertMetersToYards, convertYardsToMeters, convertYardsToMiles, dateCompare, deleteUndefinedKeys, difference, doNothing, enumFromValue, enumFromValueTypesafe, enumOrUndefinedFromValue, exhaustiveCheck, fetchImageAsBase64, filterByMultiple, formatAddress, formatCoordinates, formatSiDistance, formatUsCustomaryDistance, fuzzySearch, getAllColors, getCountryName, getDifferenceBetweenDates, getEndOfDay, getFirstLevelObjectPropertyDifferences, getISOStringFromDate, getLoremIpsum, getMimeTypeFromDataURL, getResizedDimensions, getStartOfDay, groupBy, groupTinyDataToOthers, hourIntervals, intersection, isArrayEqual, isSortByProperty, isSorted, isUUID, isValidImage, loadSVGDimensions, nonNullable, numberCompare, numberCompareUnknownAfterHighest, objNotEmpty, objectEntries, objectFromEntries, objectKeys, objectValues, parseTailwindArbitraryValue, pick, preload, removeLeftPadding, removeProperties, removeProperty, replaceNullableNumbersWithZero, resizeBlob, resizeImage, rgb2hex, size, stringCompare, stringCompareFromKey, stringNaturalCompare, stripHiddenCharacters, svgToPNG, titleCase, toID, toIDs, toPNG, toUUID, trimIds, trimPath, truthy, unionArraysByKey, uuidv3, uuidv4, uuidv5 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/shared-utils",
3
- "version": "1.15.57",
3
+ "version": "1.15.59",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "engines": {
6
6
  "node": ">=24.x"
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Resolve a country code to its localized, user-friendly country name.
3
+ *
4
+ * @param countryCode - ISO 3166-1 alpha-2 country code, e.g. "DK". Matching is case-insensitive: the code is normalized to upper-case before lookup.
5
+ * @param languages - Preferred display languages, typically `i18n.languages` (may be undefined before i18next is ready).
6
+ * @returns {string} The localized country name, or the original code when it cannot be resolved.
7
+ */
8
+ export declare const getCountryName: (countryCode: string, languages: ReadonlyArray<string> | undefined) => string;
package/src/index.d.ts CHANGED
@@ -12,6 +12,7 @@ export * from "./enumUtils";
12
12
  export * from "./exhaustiveCheck";
13
13
  export * from "./fastArrayOperations";
14
14
  export * from "./filter";
15
+ export * from "./getCountryName";
15
16
  export * from "./groupBy/groupBy";
16
17
  export * from "./GroupingUtility";
17
18
  export * from "./idUtils";