/** * Chip text for a picked checkout service. */ import type { Service } from '../../../types/quote'; /** * "Courier – Service", so several services from one courier can be told apart. When the service * name is missing (some services repeat the courier, e.g. "Evri Collection", and their name is * empty once the courier is taken out) or is only the slug, the courier alone; the slug last. * * @param service Picked service. * @return Chip text. */ export function serviceChipLabel(service: Service): string { // Saved names can start with a dash left over from taking the courier out ("- Drop Off"). const name = service.name && service.name !== service.slug ? service.name.trim().replace(/^[\s\-–—:,]+/, '') : ''; const courier = service.courier ? service.courier.trim() : ''; if (courier && name) { return `${courier} – ${name}`; } return courier || name || service.slug; }