Skip to content
This repository has been archived by the owner on Nov 6, 2021. It is now read-only.

Commit

Permalink
feat: update typings for getGamesAmerica
Browse files Browse the repository at this point in the history
This also removes the previously deprecated `game_code` property

BREAKING CHANGE: `parseGameCode` has no longer been able to parse
American games due to API changes. Until now you would get an empty
string back and a deprecation warning.
Starting this version you will instead get `null`
back and the deprecation warning has been removed.
  • Loading branch information
favna committed Jun 18, 2021
1 parent 523e2a5 commit 5b162b4
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 76 deletions.
12 changes: 1 addition & 11 deletions __tests__/parseGameCode.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { parseGameCode, Region } from '../src';
import { AMERICAN_GAME, AMERICAN_GAME_WITH_GAME_CODE, EUROPEAN_GAME, JAPANESE_GAME } from './testUtils';
import { EUROPEAN_GAME, JAPANESE_GAME } from './testUtils';

describe('Success: parseGameCode', () => {
test('Region == AMERICAS', () => {
const data = parseGameCode(AMERICAN_GAME, Region.AMERICAS);
expect(data).toBe('');
});

test('GIVEN American game with game_code AND Region == AMERICAS', () => {
const data = parseGameCode(AMERICAN_GAME_WITH_GAME_CODE, Region.AMERICAS);
expect(data).toBe('AACC');
});

test('Region == ASIA', () => {
const data = parseGameCode(JAPANESE_GAME, Region.ASIA);
expect(typeof data).toBe('string');
Expand Down
58 changes: 25 additions & 33 deletions __tests__/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,40 +95,32 @@ export const EUROPEAN_GAME: GameEU = {
};

export const AMERICAN_GAME: GameUS = {
buyitnow: true,
buyonline: true,
ca_price: 64.99,
categories: { category: ['Party', 'Multiplayer', 'Action'] },
digitaldownload: false,
eshop_price: 49.99,
free_to_start: false,
front_box_art: 'https://media.nintendo.com/nintendo/bin/oiM2QlLg9frNJhSWvFGmi5NAvEAGlYVx/_3d_ldcR3G0YQl590uHXZ89Jmouu5aS9.png',
id: 'QY7EtPDIW1WGVWSEkQ7ZVLvCFvonU-Wl',
availability: [],
boxart: 'https://media.nintendo.com/nintendo/bin/oiM2QlLg9frNJhSWvFGmi5NAvEAGlYVx/_3d_ldcR3G0YQl590uHXZ89Jmouu5aS9.png',
description: '',
developers: [],
esrbDescriptors: [],
esrbRating: '',
featured: false,
franchises: [],
freeToStart: false,
generalFilters: [],
genres: ['Party', 'Multiplayer', 'Action'],
horizontalHeaderImage: '',
howToShop: [],
lastModified: 1624052460484,
lowestPrice: 49.99,
msrp: 49.99,
nsuid: '70010000000141',
number_of_players: '2 players simultaneous',
release_date: 'Mar 3, 2017',
numOfPlayers: '2 players simultaneous',
objectID: 'QY7EtPDIW1WGVWSEkQ7ZVLvCFvonU-Wl',
platform: 'Nintendo Switch',
playerFilters: [],
priceRange: '',
publishers: [],
releaseDateDisplay: '2017-03-03T00:00:00.000Z',
salePrice: null,
slug: '1-2-switch',
system: 'Nintendo Switch',
title: '1-2-Switch',
video_link: 'h1OTBqODE64B-g16PJeQj6tifbVKl_v8'
};

export const AMERICAN_GAME_WITH_GAME_CODE: GameUS = {
game_code: 'HACPAACCA',
buyitnow: true,
buyonline: true,
ca_price: 64.99,
categories: { category: ['Party', 'Multiplayer', 'Action'] },
digitaldownload: false,
eshop_price: 49.99,
free_to_start: false,
front_box_art: 'https://media.nintendo.com/nintendo/bin/oiM2QlLg9frNJhSWvFGmi5NAvEAGlYVx/_3d_ldcR3G0YQl590uHXZ89Jmouu5aS9.png',
id: 'QY7EtPDIW1WGVWSEkQ7ZVLvCFvonU-Wl',
nsuid: '70010000000141',
number_of_players: '2 players simultaneous',
release_date: 'Mar 3, 2017',
slug: '1-2-switch',
system: 'Nintendo Switch',
title: '1-2-Switch',
video_link: 'h1OTBqODE64B-g16PJeQj6tifbVKl_v8'
url: ''
};
9 changes: 1 addition & 8 deletions src/lib/other/parseGameCode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { deprecate } from 'util';
import { EU_GAME_CODE_REGEX, JP_GAME_CODE_REGEX, Region, US_GAME_CODE_REGEX } from '../utils/constants';
import { EU_GAME_CODE_REGEX, JP_GAME_CODE_REGEX, Region } from '../utils/constants';
import type { GameEU, GameJP, GameUS } from '../utils/interfaces';

/**
Expand All @@ -20,12 +19,6 @@ export const parseGameCode = (game: GameUS | GameEU | GameJP, region: Region): s
case Region.ASIA:
codeParse = JP_GAME_CODE_REGEX.exec((game as GameJP).InitialCode);
break;
case Region.AMERICAS:
return deprecate(
() => (US_GAME_CODE_REGEX.exec((game as GameUS).game_code!)?.length || false ? US_GAME_CODE_REGEX.exec((game as GameUS).game_code!)![1] : ''),
'game_code is no longer returned by the API for American games so it can no longer be parsed from the data.',
'DEP0001'
)();
}

return codeParse && codeParse.length > 1 ? codeParse[1] : null;
Expand Down
76 changes: 52 additions & 24 deletions src/lib/utils/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import type { Country } from 'country-data';
import type { Region } from './constants';

/** @internal */
interface Category {
/** Categories array */
category: string[];
}

export interface GameEU {
age_rating_type: string;
age_rating_value: string;
Expand Down Expand Up @@ -177,29 +171,63 @@ export interface Nsuid {
}

export interface GameUS {
/** @deprecated Product code. Can be parsed for a region wide code. */
game_code?: string;
buyonline: boolean;
front_box_art: string;
/** Unix timestamp when this entry was last edited on the API */
lastModified: number;
/** The title of the game */
title: string;
/** A longer description about this title */
description: string;
/** The URL to the game on {@linkplain https://nintendo.com}. Prepend `https://nintend.com` to this URL to get a fully qualified URL to the game. */
url: string;
/** USA eShop price (in dollars) */
eshop_price: number;
/** 14-digit game unique identifier */
nsuid: string;
video_link: string;
number_of_players: string;
/** Canada eShop price (in canadian dollars) */
ca_price: number;
id: string;
title: string;
/** Gaming platform */
system: string;
free_to_start: boolean;
digitaldownload: boolean;
release_date: string;
categories: Category;
/** Game URL name */
slug: string;
buyitnow: boolean;
/** The boxart of this title, if this is an eShop game then it is the homescreen icon */
boxart: string;
/** A larger header image */
horizontalHeaderImage: string;
/** The platform on which this game was released */
platform: string;
/** The date this game was released in the {@linkplain https://en.wikipedia.org/wiki/ISO_8601 ISO 8601 Extended Format} */
releaseDateDisplay: string;
/** The {@linkplain https://www.esrb.org ESRB} rating this game was given */
esrbRating: string;
/** The amount of players this game supports. This is a string because Nintendo is more verbose than just a number. */
numOfPlayers: string;
/** Whether this game is featured on {@linkplain https://nintendo.com}'s homepage */
featured: boolean;
/** Whether this game is free to start and only needs payment later */
freeToStart: boolean;
/** An array of ESRB descriptions such as `"Alcohol Reference"` and `"Violence"` */
esrbDescriptors: string[];
/** The franches this game is part of */
franchises: string[];
/** The genres this this game is part of */
genres: string[];
/** The studios that published this game */
publishers: string[];
/** The studios that developed this gamme */
developers: string[];
/** Qualifiers that could be used to find this game when applying filters on {@linkplain https://nintendo.com} */
generalFilters: string[];
/** A list of ways this game can be purchased */
howToShop: string[];
/** Qualifiers that could be used to find this game when applying player filters on {@linkplain https://nintendo.com} */
playerFilters: string[];
/** The predefined price range in which this game falls, can be used when applying filters on {@linkplain https://nintendo.com} */
priceRange: string;
/** The {@linkplain https://en.wikipedia.org/wiki/List_price Manufacturer's Suggested Retail Price} for this game (in United States Dollars). */
msrp: number;
/** The price for this game when it is on sale. This is `null` when the game is _not_ on sale. */
salePrice: number | null;
/** The lowest price this game was ever available for. */
lowestPrice: number;
/** Identifiers about the availability of this game. */
availability: string[];
/** The internal ID that Nintendo has assigned to this game in their API. This doesn't really serve any use. */
objectID: string;
}

/** @internal */
Expand Down

0 comments on commit 5b162b4

Please sign in to comment.