Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .bitmap
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
1 change: 1 addition & 0 deletions components/utils/format-price/format-price.docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions components/utils/format-price/format-price.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
3 changes: 3 additions & 0 deletions components/utils/format-price/format-price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading