bcv-divisas
Version:
este paquete se encarga de realizar la consulta de las divisas listadas en la pagina web del banco central de venezuela como lo es el USD, EUR entre otros mas
115 lines (92 loc) • 3.37 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: index.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: index.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const axios = require('axios')
const https = require('https')
const cheerio = require('cheerio')
const httpsAgent = new https.Agent({ rejectUnauthorized: false })
/**
* asynchronous method, get the currency values from the BCV website, the web site update daily
* @async
* @method bcvDolar
* @example <caption> example usage of bcvDolar </caption>
* dtDolar().then(data=>{console.log(data)})
* @yields {Promise} Promise object that contains the following propierties '_dolar','_euro','_yuan','_lira','_rublo', all are number type
*/
const bcvDolar = async() => {
const result=await axios.get('https://www.bcv.org.ve',{httpsAgent})
const $ =cheerio.load(result.data)
const dolar = formato($('#dolar').text())
const euro = formato($('#euro').text(),1)
const yuan = formato($('#yuan').text(),2)
const lira = formato($('#lira').text(),3)
const rublo = formato($('#rublo').text(),4)
return {
_dolar: dolar,
_euro: euro,
_yuan: yuan,
_lira: lira,
_rublo: rublo
}
}
/**
* asynchronous method, get the currency values from the DolarToday website, the web site update daily
* @async
* @method dtDolar
* @example <caption> example usage of dtDolar </caption>
* dtDolar().then(data=>{console.log(data)})
* @yields {Promise} Promise object that contains the following propierties '_USD','_EUR','_COL', all are number type
*/
const dtDolar = async()=>{
const rest= await axios.get('https://s3.amazonaws.com/dolartoday/data.json',{httpsAgent})
return {
_USD:rest.data.USD,
_EUR:rest.data.EUR,
_COL:rest.data.COL
}
}
const formato = (str,int=0)=>{
const monedas = ['USD','EUR','CNY','TRY','RUB']
const valor=str
.replace(/(\r\n|\n|\r)/gm, "")
.replace(monedas[int],"")
.trim()
.replace(',','.')
const res=parseFlt(valor)
return res
}
const parseFlt = (str,int=2)=>{
const res=parseFloat(str).toFixed(int)
return res
}
module.exports = {bcvDolar,dtDolar}
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#bcvDolar">bcvDolar</a></li><li><a href="global.html#dtDolar">dtDolar</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.0</a> on Wed Dec 07 2022 12:59:07 GMT-0400 (Venezuela Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>