@davidrebollo92/currency-exchange
Version:
Convert currencies by entering the exchange rate with a precision of 6 decimal places. It also allows you to get the exchange rate between two amounts
1 lines • 1.22 kB
Source Map (JSON)
{"mappings":"AAIA,gCAAgC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,UAUnE;AAED,gCAAgC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAUvD","sources":["src/src/index.ts","src/index.ts"],"sourcesContent":[null,"\"use strict\";\n\nimport * as currency from \"currency.js\";\n\nexport function convertCurrency(amount: number, exchangeRate: number) {\n if (typeof exchangeRate != \"number\") throw new Error(\"The exchangeRate paremeter must be a number\");\n if (!Number.isInteger(amount)) throw new Error(\"The amount parameter must be an integer without decimals\");\n\n const cAmount = currency(amount, { fromCents: true });\n const cExchangeRate = currency(exchangeRate, { precision: 6 });\n\n const amountConverted = cAmount.multiply(cExchangeRate).intValue;\n\n return amountConverted;\n}\n\nexport function getExchangeRate(from: number, to: number) {\n if (typeof from != \"number\" || typeof to != \"number\")\n throw new Error(\"The parameters entered must be of type number\");\n\n const cFrom = currency(from, { precision: 6 });\n const cTo = currency(to, { precision: 6 });\n\n const exchangeRate = cTo.divide(cFrom).value;\n\n return exchangeRate;\n}\n"],"names":[],"version":3,"file":"index.d.ts.map"}