{"version":3,"sources":["jsdelivr-header.js","/npm/hurricane-electric-bandwidth@2.0.0/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,MAAM,MAAQ,QAAQ,SAChB,QAAU,QAAQ,WAElB,oBAAsB,CAC1B,MAAO,EACP,OAAQ,IACR,OAAQ,IACR,OAAQ,KAAQ,GAGlB,OAAO,QAAU,CACf,gBAAiB,MAAM,OAAO,CAC5B,QAAS,wBACT,iBAAkB,GAAmB,OAAO,EAAO,MACnD,QAAS,MAGX,oBAAqB,SAAS,GAC5B,GAAI,aAAiB,QAA0B,iBAAT,EAAmB,CACvD,MAAM,EAAQ,EAAM,MAAM,KAAK,GACzB,EAAQ,EAAM,MAAM,KAAK,GAC/B,IAAK,MAAM,IAAU,KAAS,oBAC5B,OAAO,EAAQ,oBAAoB,EAEvC,CACA,MAAM,KACR,EAEA,eAAgB,SAAS,GACvB,OAAO,KAAK,mBAAmB,GAAU,MAAK,GACrC,KAAK,oBAAoB,IAEpC,EAEA,mBAAoB,SAAS,GAC3B,OAAO,IAAI,SAAQ,CAAC,EAAS,KACtB,EAGM,aAAoB,QAA6B,iBAAZ,EAGpB,GAAnB,EAAS,OAChB,EAAO,uBAEP,KAAK,gBAAgB,IAAI,YAAa,CAAE,OAAQ,CAAE,IAAK,KACpD,MAAK,IACJ,IAAI,EAAI,QAAQ,KAAK,EAAS,MAC9B,EAAE,4BAA4B,MAAM,CAAC,EAAG,KACtC,EAAQ,EAAE,GAAK,OAAO,IAExB,EAAO,MAAM,sBAAsB,IAEpC,OAAM,IACL,EAAO,EAAM,IAdjB,EAAO,6BAHP,EAAO,uBAmBT,GAEJ","file":"/npm/hurricane-electric-bandwidth@2.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/hurricane-electric-bandwidth@2.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const axios = require('axios');\nconst cheerio = require('cheerio');\n\nconst UNIT_CONVERSION_MAP = {\n  'b/s': 1,\n  'kb/s': 1000,\n  'mb/s': 1000 ** 2,\n  'gb/s': 1000 ** 3\n};\n\nmodule.exports = {\n  requestInstance: axios.create({\n    baseURL: 'http://traffic.he.net',\n    paramsSerializer: params => { return `key=${params.key}`; },\n    timeout: 20000\n  }),\n\n  parseBandwidthSpeed: function(input) {\n    if (input instanceof String || typeof input == 'string') {\n      const value = input.split(' ')[0];\n      const units = input.split(' ')[1];\n      if (!isNaN(value) && units in UNIT_CONVERSION_MAP) {\n        return value * UNIT_CONVERSION_MAP[units];\n      }\n    }\n    throw Error; // Yes this is super lame and vague...\n  },\n\n  bandwidthBytes: function(graphKey) {\n    return this.scrapBandwidthText(graphKey).then(bandwidthText => {\n      return this.parseBandwidthSpeed(bandwidthText);\n    });\n  },\n\n  scrapBandwidthText: function(graphKey) {\n    return new Promise((resolve, reject) => {\n      if (!graphKey) {\n        reject('graphKey is required');\n      }\n      else if (!(graphKey instanceof String || typeof graphKey == 'string')) {\n        reject('graphKey must be a string');\n      }\n      else if (graphKey.length == 0) {\n        reject('grapKey is required');\n      } else {\n        this.requestInstance.get('/port.php', { params: { key: graphKey } })\n          .then(response => {\n            let $ = cheerio.load(response.data);\n            $('div.graph95 div.graphnum').each( (i, elm) => {\n              resolve($(elm).text());\n            });\n            reject(Error('Element not found.'));\n          })\n          .catch(error => {\n            reject(error);\n          });\n      }\n    });\n  },\n};\n"]}