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ACjB,EAAI,UAA6B,IAAjB,EAAK,WAErB,EAAI,MAAQ,8CAGP,EACT,EAEA,OAAO,QAAU","file":"/npm/prototype-open-exchange-rates@0.3.1/open-exchange-rates.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/prototype-open-exchange-rates@0.3.1/open-exchange-rates.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * open-exchange-rates npm module - v0.3\n * by Open Exchange Rates - https://openexchangerates.org\n *\n * nodeJS/npm wrapper for the Open Exchange Rates API.\n * Sign up for an API App ID here: https://openexchangerates.org/signup\n *\n * Requires: http-agent\n *\n * Basic Usage:\n *     var OpenExchangeRates = require('open-exchange-rates');\n *     var oxr = new OpenExchangeRates({app_id: 'YOUR_APP_ID'});\n *     oxr.latest(function(error) {\n *         // `error` or `oxr.error` contains debug info\n *         // if no error, `oxr.rates` and `oxr.base` are available\n *     });\n *\n * See example.js for full usage example.\n * See readme.md for advanced queries and usage.\n */\nfunction OpenExchangeRates(opts) {\n  // Module version:\n  this.version = '0.3';\n\n  // API base URL:\n  this.api_url = 'http://openexchangerates.org/api/';\n\n  // The default base currency ('USD'):\n  this.base = 'USD';\n\n  // The rates object:\n  this.rates = {};\n\n  // If something goes wrong, details will be stored in `oxr.error`:\n  this.error = '';\n\n  this.app_id = opts.app_id;\n}\n\n// Loads `latest.json` (latest rates)\nOpenExchangeRates.prototype.latest = function(callback) {\n  this.load('latest.json', callback);\n  return this;\n}\n\n// Loads `historical/yyyy-mm-dd.json` (historical rates)\n// `date` must be in format `'YYYY-MM-DD'`, e.g. `'2001-12-31'`\nOpenExchangeRates.prototype.historical = function(date, callback) {\n  this.load('historical/' + date + '.json', callback);\n  return this;\n}\n\nOpenExchangeRates.prototype.load = function(path, callback) {\n  // Default parameters:\n  if (typeof path === 'function') callback = path;\n  path = (typeof path === 'string') ? path : 'latest.json';\n\n  // Build API URL\n  var url = this.api_url + path + '?app_id=' + this.app_id + '&base=' + this.base;\n\n  // Create the http-agent that will grab the data:\n  var agent = require('http-agent').create('', [{\n    method: 'GET',\n    uri: url\n  }]);\n\n  agent.addListener('next', function (err, agent) {\n    var data = (agent && agent.body) ? agent.body : null;\n    this.error = err;\n\n    // Parse the API response:\n    if ( !this.error ) {\n      this.parse.call(this, data, this);\n    }\n\n    // Fire callback function, passing in any error and the raw data:\n    if ( typeof callback === 'function' ) {\n      callback(this.error, data);\n    }\n  }.bind(this));\n\n  // Start http-agent:\n  agent.start();\n  return this;\n}\n\n// The parse callback function takes the raw API data and parses/validates it.\nOpenExchangeRates.prototype.parse = function(data, oxr) {\n  // Try to parse the data as JSON:\n  try {\n    data = JSON.parse(data);\n  } catch(err) {\n    oxr.error = 'Module error in parsing JSON data: ' + err.toString();\n    return oxr;\n  }\n\n  // If the API returned an error message:\n  if ( data && data.error ) {\n    // Create debug message from API error:\n    oxr.error = data.status + ' (' + data.message + '): ' + data.description;\n    return oxr;\n  }\n\n  // The standard API response contains the base currency, an object of\n  // exchange rates, and the timestamp of when the rates were published:\n  if ( data && data.base && data.rates ) {\n    oxr.base = data.base;\n    oxr.rates = data.rates;\n    oxr.timestamp = data.timestamp * 1000; // (unix to ms)\n  } else {\n    oxr.error = 'No rates or base currency returned from API';\n  }\n\n  return oxr;\n};\n\nmodule.exports = OpenExchangeRates;\n"]}