refactoring

This commit is contained in:
2025-11-30 02:07:08 +01:00
parent 5c665ea2fe
commit af14526ae2
33 changed files with 4014 additions and 2131 deletions

View File

@@ -10,7 +10,7 @@ export class CheckoutPrice {
static fromString(priceStr: string): CheckoutPrice {
const trimmed = priceStr.trim();
if (!trimmed.startsWith('$')) {
throw new Error('Invalid price format: missing dollar sign');
}
@@ -21,13 +21,13 @@ export class CheckoutPrice {
}
const numericPart = trimmed.substring(1).replace(/,/g, '');
if (numericPart === '') {
throw new Error('Invalid price format: no numeric value');
}
const amount = parseFloat(numericPart);
if (isNaN(amount)) {
throw new Error('Invalid price format: not a valid number');
}
@@ -35,6 +35,14 @@ export class CheckoutPrice {
return new CheckoutPrice(amount);
}
/**
* Factory for a neutral/zero checkout price.
* Used when no explicit price can be extracted from the DOM.
*/
static zero(): CheckoutPrice {
return new CheckoutPrice(0);
}
toDisplayString(): string {
return `$${this.amountUsd.toFixed(2)}`;
}