UNPKG

uefa-api

Version:

Typescript bindings and utils for the UEFA APIs

3 lines (2 loc) 4.77 kB
var r,t="https://match.uefa.com/v5/matches",e=function(r,t){try{var e=new URLSearchParams(t).toString();return Promise.resolve(fetch(r+"?"+e)).then(function(r){if(!r.ok)throw new Error("Could not fetch data from API (HTTP "+r.status+")");return Promise.resolve(r.json()).then(function(r){if(void 0!==r.error)throw new Error("API returned an error: "+r.error.title+", "+r.error.message);return r})})}catch(r){return Promise.reject(r)}},o=function(r){if(void 0!==r)return Array.isArray(r)?r.join(","):r.toString()},i=function(r,t){if(r<1)throw new Error("Limit must be greater than 0");if(t<0)throw new Error("Offset must be greater than or equal to 0")},n=function(){return e("https://match.uefa.com/v5/livescore",{})};!function(r){r.ASCENDING="ASC",r.DESCENDING="DESC"}(r||(r={}));var s=function(n,s,a,d){void 0===a&&(a=10),void 0===d&&(d=0);try{if(void 0===s&&(s=r.ASCENDING),!n||!(n.competitionId||n.groupId||n.opponentTeamIds||n.matchId||n.seasonYear))throw new Error("At least one filter criteria must be provided");if(n.competitionId&&!n.seasonYear)throw new Error("Season year must be provided when filtering by competition id");i(a,d);var c={};return n.competitionId&&(c.competitionId=n.competitionId.toString()),n.matchId&&(c.matchId=o(n.matchId)),n.opponentTeamIds&&(c.opponentTeamIds=o(n.opponentTeamIds)),n.groupId&&(c.groupId=n.groupId.toString()),n.seasonYear&&(c.seasonYear=n.seasonYear.toString()),n.matchId||(c.limit=a.toString(),c.offset=d.toString()),c.order=s,Promise.resolve(e(t,c))}catch(r){return Promise.reject(r)}},a=function(t){try{if(!t||""===t)throw new Error("Match id must be provided");return Promise.resolve(s({matchId:t},r.ASCENDING,1,0)).then(function(r){if(0===r.length)throw new Error("Match with id "+t+" not found");return r[0]})}catch(r){return Promise.reject(r)}},d=function(r){try{if(!r||""===r)throw new Error("Match id must be provided");return Promise.resolve(e("https://matchstats.uefa.com/v1/team-statistics/"+r,{}))}catch(r){return Promise.reject(r)}},c=function(o,i,n,s){void 0===n&&(n=10),void 0===s&&(s=0);try{if(void 0===i&&(i=r.ASCENDING),!o||""===o)throw new Error("Match id must be provided");return Promise.resolve(e(t+"/"+o+"/events",{filter:"LINEUP",order:i,limit:n.toString(),offset:s.toString()}))}catch(r){return Promise.reject(r)}},m=function(r){try{if(!r||""===r)throw new Error("Match id must be provided");return Promise.resolve(e(t+"/"+r+"/lineups",{}))}catch(r){return Promise.reject(r)}},u=function(r,t,n){void 0===t&&(t=10),void 0===n&&(n=0);try{if(!r||!r.competitionId&&!r.playerIds&&!r.seasonYear)throw new Error("At least one filter criteria must be provided");if(r.competitionId&&!r.seasonYear)throw new Error("Season year must be provided when filtering by competition id");i(t,n);var s={};return r.competitionId&&(s.competitionId=r.competitionId.toString()),r.playerIds&&(s.playerIds=o(r.playerIds)),r.seasonYear&&(s.seasonYear=r.seasonYear.toString()),r.playerIds||(s.limit=t.toString(),s.offset=n.toString()),Promise.resolve(e("https://comp.uefa.com/v2/players",s))}catch(r){return Promise.reject(r)}},p=function(r){try{if(!r||!(r.competitionId||r.roundId||r.groupIds||r.phase||r.seasonYear))throw new Error("At least one filter criteria must be provided");if(r.competitionId&&!r.seasonYear)throw new Error("Season year must be provided when filtering by competition id");var t={};return r.competitionId&&(t.competitionId=r.competitionId.toString()),r.roundId&&(t.roundId=o(r.roundId)),r.groupIds&&(t.groupIds=o(r.groupIds)),r.phase&&(t.phase=r.phase.toString()),r.seasonYear&&(t.seasonYear=r.seasonYear.toString()),Promise.resolve(e("https://standings.uefa.com/v1/standings",t))}catch(r){return Promise.reject(r)}},I=function(r,t,n){void 0===t&&(t=10),void 0===n&&(n=0);try{if(!r||!(r.competitionId||r.roundIds||r.teamIds||r.associationId||r.seasonYear))throw new Error("At least one filter criteria must be provided");if(r.competitionId&&!r.seasonYear)throw new Error("Season year must be provided when filtering by competition id");i(t,n);var s={};return r.competitionId&&(s.competitionId=r.competitionId.toString()),r.roundIds&&(s.roundIds=o(r.roundIds)),r.teamIds&&(s.teamIds=o(r.teamIds)),r.associationId&&(s.associationId=r.associationId.toString()),r.seasonYear&&(s.seasonYear=r.seasonYear.toString()),r.teamIds||(s.limit=t.toString(),s.offset=n.toString()),Promise.resolve(e("https://comp.uefa.com/v2/teams",s))}catch(r){return Promise.reject(r)}},h=function(r){var t=o(r);return e("https://comp.uefa.com/v2/competitions",t?{competitionIds:t}:{})};export{r as SortOrder,h as getCompetitions,m as getLineups,n as getLivescore,a as getMatch,c as getMatchEvents,d as getMatchStats,s as getMatches,u as getPlayers,p as getStandings,I as getTeams}; //# sourceMappingURL=index.module.js.map