Skip to content

Commit

Permalink
refactor: use named functions for exported functions
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Apr 13, 2023
1 parent f36900d commit 8ca9ba8
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/lib/getGames/getGamesAmerica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { arrayRemoveDuplicates, EshopError } from '../utils/utils';
*
* @returns Promise containing all the games
*/
export const getGamesAmerica = async (): Promise<GameUS[]> => {
export async function getGamesAmerica(): Promise<GameUS[]> {
const page = 0;

const baseParameters: Omit<ParamsObject, 'facetFilters'> = {
Expand Down Expand Up @@ -85,7 +85,7 @@ export const getGamesAmerica = async (): Promise<GameUS[]> => {

allGames = arrayRemoveDuplicates(allGames, 'slug');
return allGames;
};
}

interface Request {
indexName: string;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/getGames/getGamesBrazil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { arrayRemoveDuplicates, EshopError } from '../utils/utils';
*
* @returns Promise containing all the games
*/
export const getGamesBrazil = async (): Promise<GameUS[]> => {
export async function getGamesBrazil(): Promise<GameUS[]> {
const page = 0;

const baseParameters: Omit<ParamsObject, 'facetFilters'> = {
Expand Down Expand Up @@ -85,7 +85,7 @@ export const getGamesBrazil = async (): Promise<GameUS[]> => {

allGames = arrayRemoveDuplicates(allGames, 'slug');
return allGames;
};
}

interface Request {
indexName: string;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/getGames/getGamesEurope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { EshopError } from '../utils/utils';
* @param options - Request options to pass to the eShop request {@link EURequestOptions | See EURequestOptions for details}
* @returns Promise containing all requested EU/PAL games
*/
export const getGamesEurope = async (options: EURequestOptions = { limit: EU_GAME_LIST_LIMIT, locale: EU_DEFAULT_LOCALE }): Promise<GameEU[]> => {
export async function getGamesEurope(options: EURequestOptions = { limit: EU_GAME_LIST_LIMIT, locale: EU_DEFAULT_LOCALE }): Promise<GameEU[]> {
if (!options.limit) options.limit = EU_GAME_LIST_LIMIT;
if (!options.locale) options.locale = EU_DEFAULT_LOCALE;

Expand All @@ -33,4 +33,4 @@ export const getGamesEurope = async (options: EURequestOptions = { limit: EU_GAM
}

return gamesData.unwrap().response.docs;
};
}
4 changes: 2 additions & 2 deletions src/lib/getGames/getGamesJapan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const parser = new XMLParser();
*
* @returns Promise containing all the games
*/
export const getGamesJapan = async (): Promise<GameJP[]> => {
export async function getGamesJapan(): Promise<GameJP[]> {
const response = await Result.fromAsync(fetch(JP_GET_GAMES_URL, FetchResultTypes.Text));

if (response.isErr()) {
Expand All @@ -26,4 +26,4 @@ export const getGamesJapan = async (): Promise<GameJP[]> => {
}

return gamesJP.unwrap().TitleInfoList.TitleInfo as GameJP[];
};
}
8 changes: 4 additions & 4 deletions src/lib/getGames/getQueriedGamesAmerica.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fetch, FetchResultTypes } from '@sapphire/fetch';
import { Result } from '@sapphire/result';
import {
QUERIED_US_ALGOLIA_KEY_NEW,
QUERIED_US_ALGOLIA_KEY_OLD,
Expand All @@ -8,7 +9,6 @@ import {
} from '../utils/constants';
import type { QueriedGameResult, QueriedGamesAmericaOptions, QueriedGameUS } from '../utils/interfaces';
import { EshopError } from '../utils/utils';
import { Result } from '@sapphire/result';

/**
* Fetches a subset of games from the American e-shops as based on a given query
Expand All @@ -18,10 +18,10 @@ import { Result } from '@sapphire/result';
* @license Apache-2.0 Jeroen Claassens & Aura Román
* @copyright 2021
*/
export const getQueriedGamesAmerica = async (
export async function getQueriedGamesAmerica(
query: string,
{ hitsPerPage = 200, page = 0 }: QueriedGamesAmericaOptions = { hitsPerPage: 200, page: 0 }
): Promise<QueriedGameUS[]> => {
): Promise<QueriedGameUS[]> {
const newGamesResult = await Result.fromAsync(
fetch<QueriedGameResult>(
QUERIED_US_GET_GAMES_URL_NEW,
Expand Down Expand Up @@ -69,7 +69,7 @@ export const getQueriedGamesAmerica = async (
}

return enrichNewHitsWithOldHitData(newGamesResult.unwrap().hits, oldGamesResult.unwrap().hits);
};
}

function enrichNewHitsWithOldHitData(newHits: QueriedGameUS[], oldHits: QueriedGameUS[]) {
for (const newHit of newHits) {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/getGames/getQueriedGamesBrazil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fetch, FetchResultTypes } from '@sapphire/fetch';
import { Result } from '@sapphire/result';
import { stringify } from 'querystring';
import { QUERIED_BR_ALGOLIA_KEY, QUERIED_BR_GET_GAMES_URL, BR_ALGOLIA_HEADERS } from '../utils/constants';
import { BR_ALGOLIA_HEADERS, QUERIED_BR_ALGOLIA_KEY, QUERIED_BR_GET_GAMES_URL } from '../utils/constants';
import type { QueriedGameResult, QueriedGamesAmericaOptions, QueriedGameUS } from '../utils/interfaces';
import { EshopError } from '../utils/utils';

Expand All @@ -13,10 +13,10 @@ import { EshopError } from '../utils/utils';
* @license Apache-2.0 Jeroen Claassens & Aura Román
* @copyright 2021
*/
export const getQueriedGamesBrazil = async (
export async function getQueriedGamesBrazil(
query: string,
{ hitsPerPage = 200, page = 0 }: QueriedGamesAmericaOptions = { hitsPerPage: 200, page: 0 }
): Promise<QueriedGameUS[]> => {
): Promise<QueriedGameUS[]> {
const gamesResult = await Result.fromAsync(
fetch<QueriedGameResult>(
QUERIED_BR_GET_GAMES_URL,
Expand All @@ -43,4 +43,4 @@ export const getQueriedGamesBrazil = async (
}

return gamesResult.unwrap().hits;
};
}
4 changes: 2 additions & 2 deletions src/lib/getShops/getActiveShops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getShopsEurope } from './getShopsEurope';
*
* @returns A list of shop objects with country code, name and default currency.
*/
export const getActiveShops = async (): Promise<EShop[]> => {
export async function getActiveShops(): Promise<EShop[]> {
try {
const shopsAmerica = await getShopsAmerica();
const shopsAsia = await getShopsAsia();
Expand All @@ -21,4 +21,4 @@ export const getActiveShops = async (): Promise<EShop[]> => {
} catch (err) {
throw err as Error;
}
};
}
4 changes: 2 additions & 2 deletions src/lib/getShops/getShopsAmerica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import type { EShop } from '../utils/interfaces';
*
* @returns A list of shop objects with country code, name and default currency.
*/
export const getShopsAmerica = async (): Promise<EShop[]> => {
export async function getShopsAmerica(): Promise<EShop[]> {
return getShopsByCountryCodes(
regions.southAmerica.countries.concat(regions.centralAfrica.countries, regions.northernAmerica.countries),
US_GAME_CHECK_CODE,
Region.AMERICAS
);
};
}
4 changes: 2 additions & 2 deletions src/lib/getShops/getShopsAsia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { EShop } from '../utils/interfaces';
*
* @returns A list of shop objects with country code, name and default currency.
*/
export const getShopsAsia = async (): Promise<EShop[]> => {
export async function getShopsAsia(): Promise<EShop[]> {
return getShopsByCountryCodes(
regions.southernAsia.countries.concat(
regions.southernAsia.countries,
Expand All @@ -22,4 +22,4 @@ export const getShopsAsia = async (): Promise<EShop[]> => {
JP_GAME_CHECK_CODE,
Region.ASIA
);
};
}
4 changes: 2 additions & 2 deletions src/lib/getShops/getShopsEurope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { EShop } from '../utils/interfaces';
*
* @returns A list of shop objects with country code, name and default currency.
*/
export const getShopsEurope = async (): Promise<EShop[]> => {
export async function getShopsEurope(): Promise<EShop[]> {
return getShopsByCountryCodes(
regions.northernEurope.countries.concat(
regions.southernEurope.countries,
Expand All @@ -23,4 +23,4 @@ export const getShopsEurope = async (): Promise<EShop[]> => {
EU_GAME_CHECK_CODE,
Region.EUROPE
);
};
}
4 changes: 2 additions & 2 deletions src/lib/other/getPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { EshopError } from '../utils/utils';
* @param prices _(Optional)_ An array of {@link TitleData}
* @returns A promise containing the pricing information.
*/
export const getPrices = async (country: string, gameIds: string[] | string, offset = 0, prices: TitleData[] = []): Promise<PriceResponse> => {
export async function getPrices(country: string, gameIds: string[] | string, offset = 0, prices: TitleData[] = []): Promise<PriceResponse> {
const filteredIds = gameIds.slice(offset, offset + PRICE_LIST_LIMIT);
const response = await Result.fromAsync(
fetch<PriceResponse>(
Expand Down Expand Up @@ -45,4 +45,4 @@ export const getPrices = async (country: string, gameIds: string[] | string, off
}

return unwrappedResponse;
};
}
4 changes: 2 additions & 2 deletions src/lib/other/getShopByCountryCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getPrices } from './getPrices';
* @param region A region id that will be appended in the final shop object for filtering purposes.
* @returns A list of shop objects with country code, name and default currency.
*/
export const getShopsByCountryCodes = async (countryCodes: string[], gameCode: string, region: Region): Promise<EShop[]> => {
export async function getShopsByCountryCodes(countryCodes: string[], gameCode: string, region: Region): Promise<EShop[]> {
const countryList: Country[] = countryCodes.map((code: string) => countries.all.filter((country: Country) => country.alpha2 === code)[0]);
const shops: PriceResponse[] = [];

Expand All @@ -39,4 +39,4 @@ export const getShopsByCountryCodes = async (countryCodes: string[], gameCode: s
if (!eShops.length) throw new Error('ACTIVE_SHOPS_Rate_Limit');

return eShops;
};
}
4 changes: 2 additions & 2 deletions src/lib/other/parseGameCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EshopError } from '../utils/utils';
* @param region Region code
* @returns The 4-digit resulting game code
*/
export const parseGameCode = (game: GameUS | GameEU | GameJP, region: Region): string | null => {
export function parseGameCode(game: GameUS | GameEU | GameJP, region: Region): string | null {
let codeParse: RegExpExecArray | null;

switch (region) {
Expand All @@ -26,4 +26,4 @@ export const parseGameCode = (game: GameUS | GameEU | GameJP, region: Region): s
}

return codeParse && codeParse.length > 1 ? codeParse[1] : null;
};
}
4 changes: 2 additions & 2 deletions src/lib/other/parseNSUID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { GameEU, GameJP, GameUS } from '../utils/interfaces';
* @param region Region code
* @returns The 14-digits NSUID
*/
export const parseNSUID = (game: GameUS | GameEU | GameJP, region: Region): string | null => {
export function parseNSUID(game: GameUS | GameEU | GameJP, region: Region): string | null {
switch (region) {
case Region.EUROPE:
return (game as GameEU).nsuid_txt ? (game as GameEU).nsuid_txt[0] : null;
Expand All @@ -20,4 +20,4 @@ export const parseNSUID = (game: GameUS | GameEU | GameJP, region: Region): stri
case Region.AMERICAS:
return (game as GameUS).nsuid;
}
};
}

1 comment on commit 8ca9ba8

@vercel
Copy link

@vercel vercel bot commented on 8ca9ba8 Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nintendo-switch-eshop – ./

nintendo-switch-eshop-git-main-favna.vercel.app
nintendo-switch-eshop.vercel.app
nintendo-switch-eshop-favna.vercel.app

Please sign in to comment.