diff --git a/.bitmap b/.bitmap index f03702d..2bba77a 100644 --- a/.bitmap +++ b/.bitmap @@ -12,30 +12,37 @@ "models/cart-item": { "name": "models/cart-item", "scope": "bitdev.git-sync-demo", - "version": "0.0.1", + "version": "0692c168065fe6f7d8f9856aa9b0e216cc94aafc", "mainFile": "index.ts", "rootDir": "components/models/cart-item" }, "ui/cart-summary": { "name": "ui/cart-summary", "scope": "bitdev.git-sync-demo", - "version": "0.0.1", + "version": "6421a3e9892fa8d619b7dfedce13414c4bb72422", "mainFile": "index.ts", "rootDir": "components/ui/cart-summary" }, "ui/price-tag": { "name": "ui/price-tag", "scope": "bitdev.git-sync-demo", - "version": "0.0.1", + "version": "d9ef38c87fe01a1693f5b43bb35bb84363d32d05", "mainFile": "index.ts", "rootDir": "components/ui/price-tag" }, "utils/format-price": { "name": "utils/format-price", "scope": "bitdev.git-sync-demo", - "version": "0.0.1", + "version": "12498fd2e619ea938672901ecb9e1bad9b811125", "mainFile": "index.ts", "rootDir": "components/utils/format-price" }, - "$schema-version": "17.0.0" + "$schema-version": "17.0.0", + "_bit_lane": { + "id": { + "name": "hello", + "scope": "bitdev.git-sync-demo" + }, + "exported": true + } } \ No newline at end of file diff --git a/components/utils/format-price/format-price.docs.mdx b/components/utils/format-price/format-price.docs.mdx index 175260a..8654221 100644 --- a/components/utils/format-price/format-price.docs.mdx +++ b/components/utils/format-price/format-price.docs.mdx @@ -11,6 +11,7 @@ import { formatPrice } from '@bitdev/git-sync-demo.utils.format-price'; formatPrice(1999.5); // "$1,999.50" formatPrice(12, 'EUR', 'de-DE'); // "12,00 €" +formatPrice(Number.NaN); // throws a RangeError ``` This is the component that the diff --git a/components/utils/format-price/format-price.spec.ts b/components/utils/format-price/format-price.spec.ts index 8e7d629..60b2c7e 100644 --- a/components/utils/format-price/format-price.spec.ts +++ b/components/utils/format-price/format-price.spec.ts @@ -11,3 +11,7 @@ it('formats another currency', () => { it('keeps two decimals for a whole number', () => { expect(formatPrice(3)).toEqual('$3.00'); }); + +it('rejects an amount that is not a finite number', () => { + expect(() => formatPrice(Number.NaN)).toThrow(RangeError); +}); diff --git a/components/utils/format-price/format-price.ts b/components/utils/format-price/format-price.ts index 387745e..36ad825 100644 --- a/components/utils/format-price/format-price.ts +++ b/components/utils/format-price/format-price.ts @@ -9,5 +9,8 @@ * ui/cart-summary. */ export function formatPrice(amount: number, currency = 'USD', locale = 'en-US'): string { + if (!Number.isFinite(amount)) { + throw new RangeError(`formatPrice: the amount must be a finite number, got ${amount}`); + } return new Intl.NumberFormat(locale, { style: 'currency', currency }).format(amount); }