All files / src/helpers productLabels.ts

100% Statements 13/13
50% Branches 2/4
100% Functions 2/2
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 381x 1x 1x   1x                     1x 1x 1x 1x   1x                         1x 1x 1x 1x  
import { isShippingRange } from '@/constants/common';
import { i18n } from '@/helpers/i18n';
import { isAvailability } from '@/utils/typeGuards/productbuilder';
 
/**
 * Localized label for a supplier {@link ShippingRange} (worldwide/international/
 * domestic/local). Falls back to the raw value for anything outside the known set.
 * @param range - The shipping range value.
 * @returns The translated label, or the raw value if unrecognized.
 * @example
 * ```ts
 * shippingLabel("worldwide"); // => "Worldwide" (en) / "Ogólnoświatowa" (pl)
 * ```
 * @category Helpers
 * @source
 */
export function shippingLabel(range: string): string {
  return isShippingRange(range) ? i18n(`shipping_${range}`) : range;
}
 
/**
 * Localized label for an availability value (see {@link isAvailability}). Also
 * covers the drawer's grouped filter codes (`in_stock`, `out_of_stock`, …), which
 * are a subset of the enum values. Falls back to the raw value for anything
 * outside the known set.
 * @param value - The availability value.
 * @returns The translated label, or the raw value if unrecognized.
 * @example
 * ```ts
 * availabilityLabel("in_stock"); // => "In Stock" (en) / "Dostępny" (pl)
 * ```
 * @category Helpers
 * @source
 */
export function availabilityLabel(value: string): string {
  return isAvailability(value) ? i18n(`availability_${value}`) : value;
}