{"version":3,"sources":["jsdelivr-header.js","/npm/538-polls@0.1.0/dist/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OCNS,MAAO,UAAa,qBAStB,eAAe,WAAW,EAAM,EAAO,GACrB,iBAAV,GAAuC,GAAjB,EAAO,QAChC,EAAO,gBAAiB,QACxB,EAAS,MAAM,EAAO,gBAG9B,IAAI,EAAM,8CACN,IACA,GAAO,EAAO,KACd,IACA,GAAO,EAAM,WAAa,KAC1B,IACA,GAAO,EAAS,KACpB,GAAO,aACP,IAAI,QAAY,MAAM,GACtB,OAAkB,KAAd,EAAI,OACG,UACQ,EAAI,QAAQ,KAAK,IAChC,IAAI,EAAU,GACd,IAAK,IAAK,EAAG,KAAW,EAAQ,QAAQ,UACpC,EAAQ,GAAK,IACN,EACH,IAAK,OAAO,EAAO,MAG3B,MAAO,IAAK,EACR,WAAY,OAAO,EAAQ,YAC3B,WAAY,IAAI,KAAK,EAAQ,YAC7B,UAAW,IAAI,KAAK,EAAQ,WAC5B,QAAS,IAAI,KAAK,EAAQ,SAC1B,UACH,GAGT,QAUO,eAAe,oBAAoB,EAAM,EAAO,GAC9B,iBAAV,GAAuC,GAAjB,EAAO,QAChC,EAAO,gBAAiB,QACxB,EAAS,MAAM,EAAO,gBAG9B,IAAI,EAAM,8CACN,IACA,GAAO,EAAO,KACd,IACA,GAAO,EAAM,WAAa,KAC1B,IACA,GAAO,EAAS,KACpB,GAAO,uBACP,IAAI,QAAY,MAAM,GACtB,OAAkB,KAAd,EAAI,OACG,UACO,EAAI,QAAQ,KAAK,IACxB,IAAK,EACR,KAAM,IAAI,KAAK,EAAQ,MACvB,SAAU,IAAI,KAAK,EAAQ,aAIvC,QACS,MAAO","file":"/npm/538-polls@0.1.0/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/538-polls@0.1.0/dist/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","import { types, codes } from \"./consts.js\";\n/**\n * This function returns all polling data for the given requirements\n * Note: Giving no options will return all polls (a few 10000), which takes a few seconds\n * @param type The type of poll\n * @param cycle The year the related election will be in (only even years)\n * @param entity The entity name or code (state, \"national\", person or institution based on context)\n * @returns List of all polls for the given requirements\n */\nexport async function fetchPolls(type, cycle, entity) {\n    if (typeof entity == \"string\" && entity.length == 2) {\n        if (entity.toUpperCase() in codes) {\n            entity = codes[entity.toUpperCase()];\n        }\n    }\n    let url = \"https://projects.fivethirtyeight.com/polls/\";\n    if (type)\n        url += type + \"/\";\n    if (cycle)\n        url += cycle.toString() + \"/\";\n    if (entity)\n        url += entity + \"/\";\n    url += \"polls.json\";\n    let res = await fetch(url);\n    if (res.status == 404)\n        return [];\n    let polls = (await res.json()).map((poll_el) => {\n        let answers = [];\n        for (let [i, answer] of poll_el.answers.entries()) {\n            answers[i] = {\n                ...answer,\n                pct: Number(answer.pct)\n            };\n        }\n        return { ...poll_el,\n            sampleSize: Number(poll_el.sampleSize),\n            created_at: new Date(poll_el.created_at),\n            startDate: new Date(poll_el.startDate),\n            endDate: new Date(poll_el.endDate),\n            answers\n        };\n    });\n    return polls;\n}\n/**\n * This function returns the polling average for a race\n * Note: The race must be uniquely identified e.g. generic-ballot 2024, or senate 2022 nevada\n * and most races don't actually have this feature\n * @param type The type of poll\n * @param cycle The year the related election will be in (only even years)\n * @param entity The entity name or code (state, person or institution based on context)\n * @returns\n */\nexport async function fetchPollingAverage(type, cycle, entity) {\n    if (typeof entity == \"string\" && entity.length == 2) {\n        if (entity.toUpperCase() in codes) {\n            entity = codes[entity.toUpperCase()];\n        }\n    }\n    let url = \"https://projects.fivethirtyeight.com/polls/\";\n    if (type)\n        url += type + \"/\";\n    if (cycle)\n        url += cycle.toString() + \"/\";\n    if (entity)\n        url += entity + \"/\";\n    url += \"polling-average.json\";\n    let res = await fetch(url);\n    if (res.status == 404)\n        return [];\n    let race = (await res.json()).map((measure) => {\n        return { ...measure,\n            date: new Date(measure.date),\n            election: new Date(measure.election)\n        };\n    });\n    return race;\n}\nexport { types, codes };\n"]}