{"size": 1053, "ext": "js", "max_stars_repo_path": "lib/rickandmorty.js", "max_stars_repo_name": "douglasPinheiro/nextjs-rickyandmorty", "max_stars_repo_stars_event_min_datetime": "2020-06-14T21:11:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-19T00:30:21.000Z", "max_issues_repo_path": "lib/rickandmorty.js", "max_issues_repo_name": "douglasPinheiro/nextjs-rickyandmorty", "max_issues_repo_issues_event_min_datetime": "2020-07-21T01:57:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-26T21:31:58.000Z", "max_forks_repo_path": "lib/rickandmorty.js", "max_forks_repo_name": "douglasPinheiro/nextjs-rickyandmorty", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 10, "max_forks_count": null, "avg_line_length": 24.488372093, "max_line_length": 88, "alphanum_fraction": 0.6277302944}
import axios from 'axios';
const basepath = 'https://rickandmortyapi.com/api/';

const returnToResultAndPage = result => {
    let characters = result.data.results;
    let pageCount = result.data.info.pages;

    return {
        characters,
        pageCount
    };
}

export async function getCharacters() {
    return returnToResultAndPage(await axios.get(`${basepath}character/`));
}

export async function getCharactersPage(page) {
    return returnToResultAndPage(await axios.get(`${basepath}character/?page=${page}`));
}

export async function getCharacter(id) {
    let result = await axios.get(`${basepath}character/${id}`);
    return result.data;
}

export async function getPageList() {
    const getResult = await axios.get(`${basepath}character/?page=1`);
    const pageCounter = getResult.data.info.pages;

    const pages = [];
    for (let i = 2; i <= pageCounter; i++) {
        pages.push(i.toString())
    }

    return pages.map(page => {
        return {
            params: {
                page
            }
        }
    })
}