@mll-lab/js-utils 2.40.0 → 2.41.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/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './array';
2
+ export * from './assert';
2
3
  export * from './date';
3
4
  export * from './device';
4
5
  export * from './error';
package/dist/index.js CHANGED
@@ -9623,6 +9623,28 @@ function soleItem(array) {
9623
9623
  return array[0];
9624
9624
  }
9625
9625
 
9626
+ /**
9627
+ * Asserts that a value is a string at runtime.
9628
+ * Throws an error if the value is not a string.
9629
+ *
9630
+ * Use this function instead of unsafe type casts like `as string` when you need
9631
+ * to ensure a value is actually a string at runtime.
9632
+ *
9633
+ * @param value - The value to check
9634
+ * @returns The value as a string if it passes the check
9635
+ * @throws Error if the value is not a string
9636
+ *
9637
+ * @example
9638
+ * const id = assertString(someUnknownValue);
9639
+ * // Now id is safely typed as string and verified at runtime
9640
+ */
9641
+ function assertString(value) {
9642
+ if (typeof value !== 'string') {
9643
+ throw new Error(`Expected a string, but got ${typeof value}`);
9644
+ }
9645
+ return value;
9646
+ }
9647
+
9626
9648
  /**
9627
9649
  * @name toDate
9628
9650
  * @category Common Helpers
@@ -16306,6 +16328,7 @@ exports.GERMAN_THOUSAND_SEPARATOR = GERMAN_THOUSAND_SEPARATOR;
16306
16328
  exports.ISO_DATE_FORMAT = ISO_DATE_FORMAT;
16307
16329
  exports.ISO_DATE_TIME_FORMAT = ISO_DATE_TIME_FORMAT;
16308
16330
  exports.SECONDLESS_DATE_TIME_FORMAT = SECONDLESS_DATE_TIME_FORMAT;
16331
+ exports.assertString = assertString;
16309
16332
  exports.callSequentially = callSequentially;
16310
16333
  exports.ceil = ceil;
16311
16334
  exports.containSameValues = containSameValues;