index.js
/**
     * Searchs AniList based on a specific term.
     * @param {String} type - Required. Either anime, manga, character, staff or studio. 
     * @param {String} term - Required. The term to lookup.
     * @param {Number} page - Which page of the results to look at. Will default to 1 if not provided.
     * @param {Number} amount - The amount of results per page. AniList will cap this at 25 and function will default to 5 if not provided.
     */
Searchs AniList based on a specific term.
@param {String} type - Required. Either anime, manga, character, staff or studio.
@param {String} term - Required. The term to lookup.
@param {Number} page - Which page of the results to look at. Will default to 1 if not provided.
@param {Number} amount - The amount of results per page. AniList will cap this at 25 and function will default to 5 if not provided.
Searchs AniList based on a specific term . @param { String } type - Required . Either anime manga character staff or studio . @param { String } term - Required . The term to lookup . @param { Number } page - Which page of the results to look at . Will default to 1 if not provided . @param { Number } amount - The amount of results per page . AniList will cap this at 25 and function will default to 5 if not provided .
search(type, term, page=1, amount=5) {
        if (!type) { throw new Error("Type of search not defined!"); }
        else if (!term) { throw new Error("Search term was not provided!"); }
        if (typeof type !== "string") { throw new Error("Type is not a string."); }
        if (typeof term !== "string") { throw new Error("Term is not a string"); }
        if (typeof page !== "number") { throw new Error("Page number is not a number"); }
        if (typeof amount !== "number") { throw new Error("Amount is not a number"); }
        var search = {
            "anime": "media (type: ANIME, search: $search) { id title { romaji english native userPreferred } }",
            "manga": "media (type: MANGA, search: $search) { id title { romaji english native userPreferred } }",
            "char": "characters (search: $search) { id name { full native } }" ,
            "staff": "staff (search: $search) { id name { full native } }",
            "studio": "studios (search: $search) { id name }"
        }
        switch (type.toLowerCase()) {
            case "anime": var query = search["anime"]; break;
            case "manga": var query = search["manga"]; break;
            case "character": var query = search["char"]; break;
            case "staff": var query = search["staff"]; break;
            case "studio": var query = search["studio"]; break;
            default: throw new Error("Type not supported.");
        }
        return Fetch.send(`query ($page: Int, $perPage: Int, $search: String) {
        Page (page: $page, perPage: $perPage) { pageInfo { total currentPage lastPage hasNextPage perPage } ${query} } }`, { search: term, page: page, perPage: amount});
    }
search ( type , term , page = 1 , amount = 5 ) { if ( ! type ) { throw new Error ( "Type of search not defined!" ) ; } else if ( ! term ) { throw new Error ( "Search term was not provided!" ) ; } if ( typeof type !== "string" ) { throw new Error ( "Type is not a string." ) ; } if ( typeof term !== "string" ) { throw new Error ( "Term is not a string" ) ; } if ( typeof page !== "number" ) { throw new Error ( "Page number is not a number" ) ; } if ( typeof amount !== "number" ) { throw new Error ( "Amount is not a number" ) ; } var search = { "anime" : "media (type: ANIME, search: $search) { id title { romaji english native userPreferred } }" , "manga" : "media (type: MANGA, search: $search) { id title { romaji english native userPreferred } }" , "char" : "characters (search: $search) { id name { full native } }" , "staff" : "staff (search: $search) { id name { full native } }" , "studio" : "studios (search: $search) { id name }" } switch ( type . toLowerCase ( ) ) { case "anime" : var query = search [ "anime" ] ; break ; case "manga" : var query = search [ "manga" ] ; break ; case "character" : var query = search [ "char" ] ; break ; case "staff" : var query = search [ "staff" ] ; break ; case "studio" : var query = search [ "studio" ] ; break ; default : throw new Error ( "Type not supported." ) ; } return Fetch . send ( ` ${ query } ` , { search : term , page : page , perPage : amount } ) ; }
Searchs AniList based on a specific term.
Searchs AniList based on a specific term .
//Validate all type conditions.