The row title, with the product name prepended only when needed.
variantRowTitle({ title: "NaBH4, min 95%" } as Product, { title: "100g" });
// => "NaBH4, min 95% 100g"
variantRowTitle({ title: "Some Product 10g" } as Product, { title: "Some Product 100g" });
// => "Some Product 100g"
export function variantRowTitle(product: Product, variant: Variant): string {
const variantTitle = typeof variant.title === 'string' ? variant.title.trim() : '';
const productTitle = typeof product.title === 'string' ? product.title.trim() : '';
if (!variantTitle) return productTitle;
const strippedParent = stripQuantityFromString(productTitle).replace(EDGE_SEPARATORS, '');
if (!strippedParent) return variantTitle;
const strippedVariant = stripQuantityFromString(variantTitle).replace(EDGE_SEPARATORS, '');
if (strippedVariant.toLowerCase().includes(strippedParent.toLowerCase())) return variantTitle;
return `${strippedParent} ${variantTitle}`;
}
Builds the display title for a flattened variant row. Some suppliers name a variant with the full product name plus size (
"NaBH4, min 95%"), others with just the size ("100g"), which is meaningless as a standalone row title. When the variant title doesn't already contain the product name, the product name (with its own quantity stripped) is prepended. Both titles have their quantity removed before the containment check, so"Some Product 10g"(parent) and"Some Product 100g"(variant) still count as already-named and aren't doubled up into"Some Product 10g Some Product 100g".