Skip to content

Commit

Permalink
If from equals to, return 100% directly (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoni Kepinski committed Jul 9, 2020
1 parent 0b5ac63 commit afef56c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/get-rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import {Rates} from './options';
*/
export default function getRate(base: string, rates: Rates, from: string | undefined, to: string | undefined): number {
if (from && to) {
// If `from` equals `to`, return 100% directly
if (from === to) {
return 1;
}

// If `from` equals `base`, return the basic exchange rate for the `to` currency
if (from === base && hasKey(rates, to)) {
return rates[to];
Expand Down

0 comments on commit afef56c

Please sign in to comment.