Skip to content

Commit afef56c

Browse files
author
Antoni Kepinski
committed
If from equals to, return 100% directly (#12)
1 parent 0b5ac63 commit afef56c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/lib/get-rate.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import {Rates} from './options';
1111
*/
1212
export default function getRate(base: string, rates: Rates, from: string | undefined, to: string | undefined): number {
1313
if (from && to) {
14+
// If `from` equals `to`, return 100% directly
15+
if (from === to) {
16+
return 1;
17+
}
18+
1419
// If `from` equals `base`, return the basic exchange rate for the `to` currency
1520
if (from === base && hasKey(rates, to)) {
1621
return rates[to];

0 commit comments

Comments
 (0)