@mll-lab/js-utils 2.30.0 → 2.32.0

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/dist/array.d.ts CHANGED
@@ -56,3 +56,5 @@ export declare function makeStringCompareFn<TSortable>(map: (sortable: TSortable
56
56
  * The empty string is first in sort order.
57
57
  */
58
58
  export declare function localeCompareStrings(a: string, b: string): number;
59
+ /** If the given array contains exactly one item, return that, otherwise null. */
60
+ export declare function soleItem<T>(array: Maybe<Array<T>>): T | null;
@@ -9527,6 +9527,13 @@ function makeStringCompareFn(map) {
9527
9527
  function localeCompareStrings(a, b) {
9528
9528
  return a.localeCompare(b);
9529
9529
  }
9530
+ /** If the given array contains exactly one item, return that, otherwise null. */
9531
+ function soleItem(array) {
9532
+ if (!array || array.length !== 1) {
9533
+ return null;
9534
+ }
9535
+ return array[0];
9536
+ }
9530
9537
 
9531
9538
  /**
9532
9539
  * @name toDate
@@ -15731,12 +15738,14 @@ function pluralize(amount, singular, plural) {
15731
15738
  function isString(value) {
15732
15739
  return typeof value === 'string';
15733
15740
  }
15741
+ function isNonEmptyString(value) {
15742
+ return isString(value) && value !== '';
15743
+ }
15734
15744
  function isNotNullish(value) {
15735
15745
  return value != null;
15736
15746
  }
15737
15747
  function isArrayOfStrings(value) {
15738
- return (value instanceof Array &&
15739
- value.every((record) => typeof record === 'string'));
15748
+ return value instanceof Array && value.every(isString);
15740
15749
  }
15741
15750
  function isEmptyObject(value) {
15742
15751
  return Boolean(value &&
@@ -15895,6 +15904,7 @@ exports.isLabID = isLabID;
15895
15904
  exports.isLabId = isLabId;
15896
15905
  exports.isMobileDevice = isMobileDevice;
15897
15906
  exports.isNonEmptyArray = isNonEmptyArray;
15907
+ exports.isNonEmptyString = isNonEmptyString;
15898
15908
  exports.isNotNullish = isNotNullish;
15899
15909
  exports.isOnlyDigits = isOnlyDigits;
15900
15910
  exports.isPartialGermanNumber = isPartialGermanNumber;
@@ -15925,6 +15935,7 @@ exports.pick = pick;
15925
15935
  exports.pluralize = pluralize;
15926
15936
  exports.pxToNumber = pxToNumber;
15927
15937
  exports.round = round;
15938
+ exports.soleItem = soleItem;
15928
15939
  exports.sortByArray = sortByArray;
15929
15940
  exports.toggleElement = toggleElement;
15930
15941
  exports.withoutIndex = withoutIndex;