UNPKG

morsel-api

Version:

Morsel api node.js package.

782 lines (684 loc) 26.8 kB
const axios = require('axios'); class MorselAPI { constructor() { } async appleAppStoreSearch(query, limit = 10, country = 'US', lang = 'en_us') { if (!query) { throw new Error('The search parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/apple/appstore/search', { params: { query, limit, country, lang } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async appleStoreSearch(query, lang = 'en') { if (!query) { throw new Error('The search parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/apple/applestore/search', { params: { query, lang } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async aoijsFunctionsSearch(query, limit = 10) { if (!query) { throw new Error('The search parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/aoijs/functions/search', { params: { query, limit } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async brawlstarsUserInfo(id) { if (!id) { throw new Error('The user ID parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/brawlstars/user/info', { params: { id } }); return response.data.info || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async colorInfo(input) { if (!input) { throw new Error('The color input parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/color/info', { params: { input } }); return response.data.info || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async deezerSearch(query, type = 'track', artist, album, label, dur_min, dur_max, bpm_min, bpm_max) { if (!query) { throw new Error('The search parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/deezer/search', { params: { query, type, artist, album, label, dur_min, dur_max, bpm_min, bpm_max } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async discordUserInfo(id) { if (!id) { throw new Error('The user ID parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/discord/user/info', { params: { id } }); return response.data.info || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async earthquakeSearch(minLat, maxLat, minLon, maxLon, start, end, minMagnitude, maxMagnitude) { if (!minLat || !maxLat || !minLon || !maxLon) { throw new Error('The parameters minLat, maxLat, minLon, and maxLon are required.'); } try { const response = await axios.get('https://morseldev.xyz/api/earthquake', { params: { minLat, maxLat, minLon, maxLon, start, end, minMagnitude, maxMagnitude } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async exchangeRate(amount, from, to) { if (amount === undefined || !from || !to) { throw new Error('The parameters amount, from, and to are required.'); } try { const response = await axios.get('https://morseldev.xyz/api/exchange', { params: { amount, from, to } }); return response.data.rate || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async fitnessCalorieNeeds(gender, age, height, weight, activityLevel) { if (!gender || !age || !height || !weight || !activityLevel) { throw new Error('The parameters gender, age, height, weight, and activityLevel are required.'); } try { const response = await axios.get('https://morseldev.xyz/api/fitness/calorie-needs', { params: { gender, age, height, weight, activityLevel } }); return response.data.calories || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async detectGender(name) { if (!name) { throw new Error('The name parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/detect/gender', { params: { name } }); return response.data.gender || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async songSearch(query) { if (!query) { throw new Error('The search parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/song/search', { params: { query } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async youtubeSearch(query, type = 'all') { const validTypes = ['all', 'videos', 'channels', 'playlists']; if (!query) { throw new Error('The search parameter is required.'); } if (!validTypes.includes(type)) { type = 'all'; } try { const response = await axios.get('https://morseldev.xyz/api/youtube/search', { params: { query, type } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async geniusArtistInfo(name) { if (!name) { throw new Error('The name parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/genius/artist/info', { params: { name } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async githubSearch(query, limit = 10, type = 'repositories', stars, language) { if (!query) { throw new Error('The search parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/github/search', { params: { query, limit, type, stars, language } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async githubUserInfo(username) { if (!username) { throw new Error('The username parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/github/user/info', { params: { username } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async googleImageSearch(query, antiNsfw = false) { if (!query) { throw new Error('The search parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/google/search/images', { params: { query, antiNsfw } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async googlePlaystoreSearch(query, limit = 10) { if (!query) { throw new Error('The search parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/google/playstore/search', { params: { query, limit } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async googleTrends(date, country = 'US') { if (!date) { throw new Error('The date parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/google/trends', { params: { date, country } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async historicalEvents(date) { if (!date) { throw new Error('The date parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/historical/events', { params: { date } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async instagramUserInfo(username) { if (!username) { throw new Error('The username parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/instagram/users/info', { params: { username } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async ipGeolocation(ip) { if (!ip) { throw new Error('The IP parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/ip/geolocation', { params: { ip } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async appleItunesSearch(query) { if (!query) { throw new Error('The query parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/apple/itunes/search', { params: { query } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async minecraftServerStatus(ip) { if (!ip) { throw new Error('The IP parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/minecraft/server/status', { params: { ip } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async movieInfo(movie) { if (!movie) { throw new Error('The movie parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/movie/info', { params: { movie } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async movieSearch(query) { if (!query) { throw new Error('The query parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/movie/search', { params: { query } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async nbaPlayerInfo(player) { if (!player) { throw new Error('The player parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/nba/players/info', { params: { player } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async news(country = 'tr') { try { const response = await axios.get('https://morseldev.xyz/api/news', { params: { country } }); return response.data.articles || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async npmPackageInfo(name) { if (!name) { throw new Error('The name parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/npm/package/info', { params: { name } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async npmPackageSearch(query, limit = 10) { if (!query) { throw new Error('The query parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/npm/package/search', { params: { query, limit } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async passwordGenerate(length = 16, includeNumbers = true, includeSymbols = false, includeUppercase = true, includeLowercase = true) { try { const response = await axios.get('https://morseldev.xyz/api/password/generate', { params: { length, includeNumbers, includeSymbols, includeUppercase, includeLowercase } }); return response.data.password || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async randomUser(gender, nationality, limit = 1, minAge, maxAge, seed, include, exclude) { try { const response = await axios.get('https://morseldev.xyz/api/random/user', { params: { gender, nationality, limit, minAge, maxAge, seed, include, exclude } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async recipes(food, cuisine, number = 1) { if (!food) { throw new Error('The food parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/recipes', { params: { food, cuisine, number } }); return response.data.recipes || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async reverseText(text) { if (!text) { throw new Error('The text parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/reverse/text', { params: { text } }); return response.data.reversed || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async robloxUserSearch(username, limit = 10) { if (!username) { throw new Error('The username parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/roblox/users/search', { params: { username, limit } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async songSuggestion(mood, genre, limit = 5) { try { const response = await axios.get('https://morseldev.xyz/api/song/suggestion', { params: { mood, genre, limit } }); return response.data.songs || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async soundcloudSearch(query) { if (!query) { throw new Error('The query parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/soundcloud/search', { params: { query } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async spotifySearch(song) { if (!song) { throw new Error('The song parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/spotify/search', { params: { song } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async steamGameInfo(name) { if (!name) { throw new Error('The name parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/steam/game-info', { params: { name } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async steamSearch(query) { if (!query) { throw new Error('The query parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/steam/search', { params: { query } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async tiktokUserInfo(username) { if (!username) { throw new Error('The username parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/tiktok/users/info', { params: { username } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async translate(text, targetLang, sourceLang) { if (!text || !targetLang) { throw new Error('The text and targetLang parameters are required.'); } try { const response = await axios.get('https://morseldev.xyz/api/translate', { params: { text, targetLang, sourceLang } }); return response.data.translation || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async trendyolSearch(query, minPrice, maxPrice) { if (!query) { throw new Error('The query parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/trendyol/search', { params: { query, minPrice, maxPrice } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async urlDetector(url) { if (!url) { throw new Error('The url parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/url/detector', { params: { url } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async wattpadSearch(query, limit, lang, mature) { if (!query) { throw new Error('The query parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/wattpad/search', { params: { query, limit, lang, mature } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async weather(location, days) { if (!location) { throw new Error('The location parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/weather', { params: { location, days } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async wikipediaSearch(query, lang) { if (!query) { throw new Error('The query parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/wikipedia/search', { params: { query, lang } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async whdIndicator(indicator) { if (!indicator) { throw new Error('The indicator parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/whd', { params: { indicator } }); return response.data || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } async youtubeMusicSearch(query, type) { if (!query) { throw new Error('The query parameter is required.'); } try { const response = await axios.get('https://morseldev.xyz/api/youtube/musics/search', { params: { query, type } }); return response.data.results || null; } catch (error) { console.error('An error occurred during the API call:', error?.response?.data?.error || error.message); return null; } } } module.exports = MorselAPI;