Skip to content

Commit

Permalink
Simplify getRate function (move from options object to plain argume…
Browse files Browse the repository at this point in the history
…nts)
  • Loading branch information
xxczaki committed Sep 6, 2019
1 parent 03142a6 commit d8a2167
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function hasKey<T>(obj: T, key: string | number | symbol): key is keyof T {
return key in obj;
}

const getRate = ({base, rates, from, to}: Options): number => {
const getRate = (base: string, rates: object, from: string, to: string): number => {
// If `from` equals `base`, return the basic exchange rate for the `to` currency
if (from === base && hasKey(rates, to)) {
return rates[to];
Expand Down Expand Up @@ -64,7 +64,7 @@ class Cashify {
return amount;
}

return (amount * 100) * getRate({base, rates, from, to}) / 100;
return (amount * 100) * getRate(base, rates, from, to) / 100;
}
}

Expand All @@ -83,7 +83,7 @@ const convert = (amount: number, {from, to, base, rates}: Options): number => {
return amount;
}

return (amount * 100) * getRate({base, rates, from, to}) / 100;
return (amount * 100) * getRate(base, rates, from, to) / 100;
};

export {
Expand Down

0 comments on commit d8a2167

Please sign in to comment.