[go: nahoru, domu]

Skip to content

Commit

Permalink
fix: don't accept extra fields inside the currency options on create (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fivism committed Nov 19, 2022
1 parent 6c0e98b commit 9e72f9e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/helpers/createDinero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export function createDinero<TAmount>({
}: CreateDineroOptions<TAmount>) {
return function dinero({
amount,
currency,
scale = currency.exponent,
currency: { code, base, exponent },
scale = exponent,
}: DineroOptions<TAmount>): Dinero<TAmount> {
const currency = { code, base, exponent };

onCreate?.({ amount, currency, scale });

return {
Expand Down
16 changes: 16 additions & 0 deletions packages/dinero.js/src/__tests__/dinero.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,20 @@ describe('dinero', () => {

expect(snapshot).toMatchObject({ amount: 500, currency: USD, scale: 2 });
});
it('cleans up unwanted properties from the options', () => {
const d = dinero({
amount: 500,
// @ts-expect-error
currency: { code: 'USD', exponent: 2, base: 10, _extraProperty: 123 },
_extraProperty: 123,
});

const snapshot = toSnapshot(d);

expect(snapshot).toStrictEqual({
amount: 500,
currency: USD,
scale: 2,
});
});
});

1 comment on commit 9e72f9e

@vercel
Copy link
@vercel vercel bot commented on 9e72f9e Nov 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

dinerojs – ./

dinerojs-git-main-dinerojs.vercel.app
dinerojs-dinerojs.vercel.app
v2.dinerojs.com

Please sign in to comment.