UNPKG

@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.64 kB
{"mappings":";;AAAA;AAAA;AAIO,SAAS,0CAAgB,MAAc,EAAE,YAAoB,EAAE;IACnE,IAAI,OAAO,gBAAgB,UAAU,MAAM,IAAI,MAAM,+CAA+C;IACpG,IAAI,CAAC,OAAO,SAAS,CAAC,SAAS,MAAM,IAAI,MAAM,4DAA4D;IAE3G,MAAM,UAAU,kBAAS,QAAQ;QAAE,WAAW,IAAI;IAAC;IACnD,MAAM,gBAAgB,kBAAS,cAAc;QAAE,WAAW;IAAE;IAE5D,MAAM,kBAAkB,QAAQ,QAAQ,CAAC,eAAe,QAAQ;IAEhE,OAAO;AACV;AAEO,SAAS,0CAAgB,IAAY,EAAE,EAAU,EAAE;IACvD,IAAI,OAAO,QAAQ,YAAY,OAAO,MAAM,UACzC,MAAM,IAAI,MAAM,iDAAiD;IAEpE,MAAM,QAAQ,kBAAS,MAAM;QAAE,WAAW;IAAE;IAC5C,MAAM,MAAM,kBAAS,IAAI;QAAE,WAAW;IAAE;IAExC,MAAM,eAAe,IAAI,MAAM,CAAC,OAAO,KAAK;IAE5C,OAAO;AACV","sources":["src/index.ts"],"sourcesContent":["\"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.mjs.map"}