mirror of
https://github.com/tcgdex/javascript-sdk.git
synced 2025-04-22 02:42:08 +00:00
V2 added typing for compiler
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
1db0b1ab38
commit
b13e554162
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,4 +3,5 @@ node_modules
|
||||
# Dist files
|
||||
*.js
|
||||
*.d.ts
|
||||
!interfaces.d.ts
|
||||
test.ts
|
||||
|
@ -1 +1,6 @@
|
||||
test.js
|
||||
.editorconfig
|
||||
.gitignore
|
||||
.npmignore
|
||||
tsconfig.json
|
||||
*.ts
|
||||
yarn.lock
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 TCGdex
|
||||
Copyright (c) 2021 TCGdex
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
@ -1,53 +0,0 @@
|
||||
import LangList, { Langs } from "./interfaces/LangList";
|
||||
import AbilityType from "./interfaces/AbilityType";
|
||||
import Category from "./interfaces/Category";
|
||||
import Rarity from "./interfaces/Rarity";
|
||||
import Tag from "./interfaces/Tag";
|
||||
import Type from "./interfaces/Type";
|
||||
|
||||
import atTrans from './translations/abilityType'
|
||||
import cTrans from './translations/category'
|
||||
import rTrans from './translations/rarity'
|
||||
import taTrans from './translations/tag'
|
||||
import tyTrans from './translations/type'
|
||||
|
||||
type possibilities = "abilityType" | "category" | "rarity" | "tag" | "type"
|
||||
|
||||
export default class TranslationUtil {
|
||||
public static translate(master: "abilityType",a: AbilityType, lang: Langs): string|undefined;
|
||||
public static translate(master: "category",a: Category, lang: Langs): string|undefined;
|
||||
public static translate(master: "rarity",a: Rarity, lang: Langs): string|undefined;
|
||||
public static translate(master: "tag",a: Tag, lang: Langs): string|undefined;
|
||||
public static translate(master: "type",a: Type, lang: Langs): string|undefined;
|
||||
public static translate(master: possibilities,a: number, lang: Langs): string|undefined {
|
||||
let langlist: LangList<Array<string>>|undefined
|
||||
switch (master) {
|
||||
case 'abilityType':
|
||||
langlist = atTrans
|
||||
break
|
||||
case 'category':
|
||||
langlist = cTrans
|
||||
break
|
||||
|
||||
case 'rarity':
|
||||
langlist = rTrans
|
||||
break
|
||||
|
||||
case 'tag':
|
||||
langlist = taTrans
|
||||
break
|
||||
|
||||
case 'type':
|
||||
langlist = tyTrans
|
||||
break
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!langlist) return
|
||||
const tmp = langlist[lang]
|
||||
if (!tmp) return
|
||||
return tmp[a]
|
||||
}
|
||||
}
|
||||
|
||||
export type translations = LangList<Array<string>>
|
234
interfaces.d.ts
vendored
Normal file
234
interfaces.d.ts
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
export type SupportedLanguages = 'en' | 'fr'
|
||||
|
||||
export type Languages<T = string> = Partial<Record<SupportedLanguages, T>>
|
||||
|
||||
interface SerieResume {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface Serie extends SerieResume {
|
||||
sets: SetList
|
||||
}
|
||||
|
||||
interface variants {
|
||||
normal?: boolean
|
||||
reverse?: boolean
|
||||
holo?: boolean
|
||||
firstEdition?: boolean
|
||||
}
|
||||
|
||||
export type Types = 'Colorless' | 'Darkness' | 'Dragon' |
|
||||
'Fairy' | 'Fightning' | 'Fire' |
|
||||
'Grass' | 'Lightning' | 'Metal' |
|
||||
'Psychic' | 'Water'
|
||||
|
||||
export type SetList = Array<SetResume>
|
||||
export type SerieList = Array<SerieResume>
|
||||
export type CardList = Array<CardResume>
|
||||
|
||||
interface SetResume {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface Set extends SetResume {
|
||||
serie: Serie
|
||||
tcgOnline?: string
|
||||
variants?: variants
|
||||
|
||||
cardCount: {
|
||||
total: number
|
||||
official: number
|
||||
}
|
||||
|
||||
releaseDate: string
|
||||
|
||||
legal?: {
|
||||
standard: boolean
|
||||
expanded: boolean
|
||||
}
|
||||
|
||||
cards: CardList
|
||||
}
|
||||
|
||||
interface CardResume {
|
||||
id: string
|
||||
localId: string
|
||||
|
||||
/**
|
||||
* Card Name (Including the suffix if next to card name)
|
||||
*/
|
||||
name: string
|
||||
image?: string
|
||||
}
|
||||
|
||||
export interface Card<SetType extends SetResume = SetResume> extends CardResume {
|
||||
|
||||
/**
|
||||
* Card illustrator
|
||||
*/
|
||||
illustrator?: string
|
||||
|
||||
/**
|
||||
* Card Rarity
|
||||
*
|
||||
* - None https://www.tcgdex.net/database/sm/smp/SM01
|
||||
* - Common https://www.tcgdex.net/database/xy/xy9/1
|
||||
* - Uncommon https://www.tcgdex.net/database/xy/xy9/2
|
||||
* - Rare https://www.tcgdex.net/database/xy/xy9/3
|
||||
* - Ultra Rare
|
||||
* - Secret Rare
|
||||
*/
|
||||
rarity: 'None' | 'Common'| 'Uncommon' | 'Rare' | 'Ultra Rare' | 'Secret Rare'
|
||||
|
||||
/**
|
||||
* Card Category
|
||||
*
|
||||
* - Pokemon
|
||||
* - Trainer
|
||||
* - Energy
|
||||
*/
|
||||
category: 'Pokemon' | 'Trainer' | 'Energy'
|
||||
|
||||
/**
|
||||
* Card Variants (Override Set Variants)
|
||||
*/
|
||||
variants?: variants
|
||||
|
||||
/**
|
||||
* Card Set
|
||||
*/
|
||||
set: SetType
|
||||
|
||||
/**
|
||||
* Pokemon only elements
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pokemon Pokedex ID
|
||||
*/
|
||||
dexId?: Array<number>
|
||||
|
||||
/**
|
||||
* Pokemon HP
|
||||
*/
|
||||
hp?: number
|
||||
|
||||
/**
|
||||
* Pokemon Types
|
||||
*/
|
||||
types?: Array<Types> // ex for multiple https://www.tcgdex.net/database/ex/ex13/17
|
||||
|
||||
/**
|
||||
* Pokemon Sub Evolution
|
||||
*/
|
||||
evolveFrom?: string
|
||||
|
||||
/**
|
||||
* Pokemon Weight
|
||||
*/
|
||||
weight?: string
|
||||
|
||||
/**
|
||||
* Pokemon Description
|
||||
*/
|
||||
description?: string
|
||||
|
||||
/**
|
||||
* Level of the Pokemon
|
||||
*
|
||||
* NOTE: can be equal to 'X' when the pokemon is a LEVEL-UP one
|
||||
*/
|
||||
level?: number | string
|
||||
|
||||
/**
|
||||
* Pokemon Stage
|
||||
*
|
||||
* - Basic https://www.tcgdex.net/database/xy/xy9/1
|
||||
* - BREAK https://www.tcgdex.net/database/xy/xy9/18
|
||||
* - LEVEL-UP https://www.tcgdex.net/database/dp/dp1/121
|
||||
* - MEGA https://www.tcgdex.net/database/xy/xy1/2
|
||||
* - RESTORED https://www.tcgdex.net/database/bw/bw5/53
|
||||
* - Stage1 https://www.tcgdex.net/database/xy/xy9/2
|
||||
* - Stage2 https://www.tcgdex.net/database/xy/xy9/3
|
||||
* - VMAX https://www.tcgdex.net/database/swsh/swsh1/50
|
||||
*/
|
||||
stage?: 'Basic' | 'BREAK' | 'LEVEL-UP' | 'MEGA' | 'RESTORED' | 'Stage1' | 'Stage2' | 'VMAX'
|
||||
|
||||
/**
|
||||
* Card Suffix
|
||||
*
|
||||
* - EX https://www.tcgdex.net/database/ex/ex2/94
|
||||
* - GX https://www.tcgdex.net/database/sm/sm12/4
|
||||
* - V https://www.tcgdex.net/database/swsh/swsh1/1
|
||||
* - Legend https://www.tcgdex.net/database/hgss/hgss1/114
|
||||
* - Prime https://www.tcgdex.net/database/hgss/hgss2/85
|
||||
* - SP https://www.tcgdex.net/database/pl/pl1/7
|
||||
* - TAG TEAM-GX https://www.tcgdex.net/database/sm/sm12/226
|
||||
*/
|
||||
suffix?: 'EX' | 'GX' | 'V' | 'Legend' | 'Prime' | 'SP' | 'TAG TEAM-GX'
|
||||
|
||||
/**
|
||||
* Pokemon Held Item
|
||||
*
|
||||
* ex https://www.tcgdex.net/database/dp/dp2/75
|
||||
*/
|
||||
item?: {
|
||||
name: string
|
||||
effect: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Pokemon Abilities
|
||||
*
|
||||
* multi abilities ex https://www.tcgdex.net/database/ex/ex15/10
|
||||
*/
|
||||
abilities?: Array<{
|
||||
type: 'Pokemon Power' | 'Poke-BODY' | 'Poke-POWER' | 'Ability' | 'Ancient Trait'
|
||||
name: string
|
||||
effect: string
|
||||
}>
|
||||
|
||||
/**
|
||||
* Pokemon Attacks
|
||||
*/
|
||||
attacks?: Array<{
|
||||
cost?: Array<Types>
|
||||
name: string
|
||||
effect?: string
|
||||
damage?: string | number
|
||||
}>
|
||||
|
||||
/**
|
||||
* Pokemon Weaknesses
|
||||
*/
|
||||
weaknesses?: Array<{
|
||||
type: Types
|
||||
value?: string
|
||||
}>
|
||||
|
||||
resistances?: Array<{
|
||||
type: Types
|
||||
value?: string
|
||||
}>
|
||||
|
||||
retreat?: number
|
||||
|
||||
//Trainer/Energy
|
||||
effect?: string
|
||||
|
||||
// Trainer Only
|
||||
trainerType?: 'Supporter' | // https://www.tcgdex.net/database/ex/ex7/83
|
||||
'Item' | // https://www.tcgdex.net/database/ex/ex7/89
|
||||
'Stadium' | // https://www.tcgdex.net/database/ex/ex7/87
|
||||
'Tool' | // https://www.tcgdex.net/database/neo/neo1/93
|
||||
'Ace Spec' | // https://www.tcgdex.net/database/bw/bw7/139
|
||||
'Technical Machine' | // https://www.tcgdex.net/database/ecard/ecard1/144
|
||||
'Goldenred Game Corner' | // https://www.tcgdex.net/database/neo/neo1/83
|
||||
'Rocket\'s Secret Machine' // https://www.tcgdex.net/database/ex/ex7/84
|
||||
|
||||
// Energy Only
|
||||
energyType?: 'Normal' | // https://www.tcgdex.net/database/ecard/ecard1/160
|
||||
'Special' // https://www.tcgdex.net/database/ecard/ecard1/158
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
import AbilityType, { AbilityTypeSimple } from "./AbilityType";
|
||||
import LangList from "./LangList";
|
||||
|
||||
export interface AbilitySingle extends AbilitySimple {
|
||||
type: AbilityTypeSimple
|
||||
text: string
|
||||
}
|
||||
|
||||
export interface AbilitySimple {
|
||||
// id: number // WIP
|
||||
name: string
|
||||
}
|
||||
|
||||
export default interface Ability {
|
||||
id?: number
|
||||
type: AbilityType
|
||||
name: LangList<string>
|
||||
text: LangList<string>
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
export interface AbilityTypeSimple {
|
||||
id: AbilityType
|
||||
name: string
|
||||
}
|
||||
|
||||
export type AbilityTypeSingle = {
|
||||
id: AbilityType
|
||||
name: string
|
||||
cards: string
|
||||
}
|
||||
|
||||
enum AbilityType {
|
||||
POKEBODY,
|
||||
POKEPOWER,
|
||||
TALENT,
|
||||
ANCIENTTRAIT
|
||||
}
|
||||
|
||||
export default AbilityType
|
@ -1,20 +0,0 @@
|
||||
import Type from "./Type";
|
||||
import LangList from "./LangList";
|
||||
|
||||
export interface AttackSingle extends AttackSimple {
|
||||
cost?: Array<string>
|
||||
text?: string
|
||||
damage?: string|number
|
||||
}
|
||||
|
||||
export interface AttackSimple {
|
||||
// id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export default interface Attack {
|
||||
cost?: Array<Type>
|
||||
name: LangList<string>
|
||||
text?: LangList<string>
|
||||
damage?: string|number
|
||||
}
|
@ -1,190 +0,0 @@
|
||||
import Type, { TypeSimple } from "./Type";
|
||||
import Tag, { TagSimple } from "./Tag";
|
||||
import { RaritySimple, Rarity } from "./Rarity";
|
||||
import { CategorySimple, Category } from "./Category";
|
||||
import { IllustratorSimple } from "./Illustrator";
|
||||
import Ability, { AbilitySingle } from "./Ability";
|
||||
import Attack, { AttackSingle } from "./Attack";
|
||||
import { List } from "./General";
|
||||
import LangList from "./LangList";
|
||||
import Set from "./Set";
|
||||
|
||||
export interface CardSimple {
|
||||
id: string
|
||||
localId: string|number
|
||||
name: string
|
||||
image: string
|
||||
}
|
||||
|
||||
export interface CardSingle {
|
||||
// General
|
||||
id: string
|
||||
|
||||
/**
|
||||
* The Set Card ID
|
||||
*/
|
||||
localId: number | string
|
||||
|
||||
/**
|
||||
* The card Name
|
||||
*/
|
||||
name: string
|
||||
|
||||
/**
|
||||
* The Card Picture
|
||||
* it doesn't contains the ext as it is available as .png, .jpg, .webp (HINT: use .webp then .png then .jpg)
|
||||
*/
|
||||
image?: {
|
||||
low: string
|
||||
high?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Card Tags
|
||||
*/
|
||||
tags?: Array<TagSimple>
|
||||
|
||||
/**
|
||||
* Card illustrator informations
|
||||
*/
|
||||
illustrator?: IllustratorSimple
|
||||
|
||||
/**
|
||||
* Card Rarity
|
||||
*/
|
||||
rarity: RaritySimple
|
||||
|
||||
/**
|
||||
* Card Category
|
||||
*/
|
||||
category: CategorySimple
|
||||
|
||||
/**
|
||||
* Card Set
|
||||
*/
|
||||
set: {
|
||||
/**
|
||||
* Set Display name
|
||||
*/
|
||||
name: string
|
||||
|
||||
/**
|
||||
* Set code/id
|
||||
*/
|
||||
code: string
|
||||
}
|
||||
|
||||
/**
|
||||
* This will be set for each cards
|
||||
* define all the variants for a specific card
|
||||
*/
|
||||
variants: {
|
||||
normal: boolean
|
||||
reverse: boolean
|
||||
holo: boolean
|
||||
firstEd: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Some Pokémons have item like a berry
|
||||
*/
|
||||
item?: {
|
||||
name: string
|
||||
effect: string
|
||||
}
|
||||
|
||||
// Pokémon only
|
||||
hp?: number
|
||||
dexId?: number
|
||||
lvl?: number
|
||||
type?: Array<TypeSimple>
|
||||
evolveFrom?: string
|
||||
evolveTo?: Array<string>
|
||||
abilities?: Array<AbilitySingle>
|
||||
attacks?: Array<AttackSingle>
|
||||
weaknesses?: Array<WeakRes>
|
||||
|
||||
resistances?: Array<WeakRes>
|
||||
retreat?: number
|
||||
|
||||
// Trainer/Energy only
|
||||
effect?: string
|
||||
}
|
||||
|
||||
export type CardList = List<CardSimple>
|
||||
|
||||
type WeakRes = {
|
||||
type: TypeSimple
|
||||
value?: string
|
||||
}
|
||||
|
||||
type Card = {
|
||||
|
||||
// global id made of setid and localId
|
||||
id: string
|
||||
|
||||
// set id
|
||||
localId: string|number
|
||||
|
||||
dexId?: number
|
||||
|
||||
// Card informations (from top to bottom of card)
|
||||
name: LangList<string>
|
||||
hp?: number //optionnal because energy/trainer cards might have not any hp
|
||||
type?: Array<Type> // ex for multiple https://www.tcgdex.net/database/ex/ex13/17
|
||||
|
||||
image?: {
|
||||
low: LangList<string>
|
||||
high?: LangList<string>
|
||||
}
|
||||
|
||||
evolveFrom?: LangList<string>
|
||||
evolveTo?: Array<LangList<string>>
|
||||
tags?: Array<Tag> // made after
|
||||
illustrator?: string
|
||||
|
||||
abilities?: Array<Ability>
|
||||
|
||||
attacks?: Array<Attack>
|
||||
|
||||
// If card is trainer or energy effect is here
|
||||
effect?: LangList<string>
|
||||
|
||||
item?: {
|
||||
name: LangList<string>
|
||||
effect: LangList<string>
|
||||
}
|
||||
|
||||
weaknesses?: Array<{
|
||||
type: Type
|
||||
value?: string
|
||||
}>
|
||||
|
||||
resistances?: Array<{
|
||||
type: Type
|
||||
value?: string
|
||||
}>
|
||||
|
||||
retreat?: number
|
||||
|
||||
rarity: Rarity
|
||||
|
||||
// Other elements
|
||||
category: Category
|
||||
set: {
|
||||
name: string
|
||||
code: string
|
||||
}| Set
|
||||
|
||||
/**
|
||||
* Override Set defaults
|
||||
*/
|
||||
cardTypes?: {
|
||||
normal: boolean
|
||||
reverse: boolean
|
||||
holo: boolean
|
||||
firstEd: boolean
|
||||
}
|
||||
}
|
||||
|
||||
export default Card
|
@ -1,24 +0,0 @@
|
||||
import { List } from "./General"
|
||||
import { CardSimple } from "./Card"
|
||||
|
||||
export enum Category {
|
||||
POKEMON,
|
||||
TRAINER,
|
||||
ENERGY
|
||||
}
|
||||
|
||||
export default Category
|
||||
|
||||
export type CategorySingle = {
|
||||
id: Category
|
||||
name: string
|
||||
cards: Array<CardSimple>
|
||||
}
|
||||
|
||||
|
||||
export type CategorySimple = {
|
||||
id: Category
|
||||
name: string
|
||||
}
|
||||
|
||||
export type CategoryList = List<CategorySimple>
|
@ -1,22 +0,0 @@
|
||||
import { SetSimple } from "./Set";
|
||||
import { List } from "./General";
|
||||
import LangList from "./LangList";
|
||||
|
||||
export type ExpansionSingle = {
|
||||
code: string
|
||||
name: string
|
||||
sets: Array<SetSimple>
|
||||
}
|
||||
|
||||
export type ExpansionSimple = {
|
||||
code: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export type ExpansionList = List<ExpansionSimple>
|
||||
|
||||
export default interface Expansion {
|
||||
name: LangList<string> | string
|
||||
code: string
|
||||
sets?: Array<string>
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
export type List<T> = {
|
||||
count: number
|
||||
list: Array<T>
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
import { CardSimple } from "./Card";
|
||||
import { List } from "./General";
|
||||
|
||||
export type HpSingle = {
|
||||
hp: number
|
||||
cards: Array<CardSimple>
|
||||
}
|
||||
|
||||
export type HpSimple = number
|
||||
|
||||
export type HpList = List<HpSimple>
|
@ -1,22 +0,0 @@
|
||||
import { CardSimple } from "./Card";
|
||||
import { List } from "./General";
|
||||
|
||||
export type IllustratorSingle = {
|
||||
id: number,
|
||||
name: string,
|
||||
cards: Array<CardSimple>
|
||||
}
|
||||
|
||||
export interface IllustratorSimple {
|
||||
id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export type IllustratorsList = List<IllustratorSimple>
|
||||
|
||||
interface Illustrator {
|
||||
id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export default Illustrator
|
@ -1,15 +0,0 @@
|
||||
type LangList<T> = {
|
||||
[key in Langs]?: T
|
||||
}
|
||||
|
||||
export type Langs = "en" | "fr"
|
||||
|
||||
namespace LangList {
|
||||
export function insert(from: LangList<any>, el: any, lang: Langs) {
|
||||
if (typeof from !== "object") from = {}
|
||||
from[lang] = el
|
||||
return from
|
||||
}
|
||||
}
|
||||
|
||||
export default LangList
|
@ -1,6 +0,0 @@
|
||||
import { Langs as l } from './LangList'
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export type Langs = l
|
@ -1,31 +0,0 @@
|
||||
import { List } from "./General"
|
||||
import { CardSimple } from "./Card"
|
||||
|
||||
export enum Rarity {
|
||||
NONE,
|
||||
COMMON,
|
||||
UNCOMMON,
|
||||
RARE,
|
||||
|
||||
// Both RAREULTRA and ULTRARARE are the same until I know the correct name
|
||||
RAREULTRA = 4,
|
||||
ULTRARARE = 4,
|
||||
|
||||
AMAZING,
|
||||
|
||||
}
|
||||
|
||||
export default Rarity
|
||||
|
||||
export interface RaritySimple {
|
||||
id: Rarity
|
||||
name: string
|
||||
}
|
||||
|
||||
export type RaritySingle = {
|
||||
id: Rarity
|
||||
name: string
|
||||
cards: Array<CardSimple>
|
||||
}
|
||||
|
||||
export type RarityList = List<RaritySimple>
|
@ -1,11 +0,0 @@
|
||||
import { CardSimple } from "./Card";
|
||||
import { List } from "./General";
|
||||
|
||||
export type RetreatSimple = number
|
||||
|
||||
export interface RetreatSingle {
|
||||
id: RetreatSimple
|
||||
cards: Array<CardSimple>
|
||||
}
|
||||
|
||||
export type RetreatList = List<RetreatSimple>
|
@ -1,163 +0,0 @@
|
||||
import { CardSimple } from "./Card";
|
||||
import { List } from "./General";
|
||||
import LangList from "./LangList";
|
||||
import Expansion from "./Expansion";
|
||||
|
||||
export type SetRequest = SetSingle
|
||||
|
||||
export interface SetSingleRaw extends SetSingle {
|
||||
releaseDate: string
|
||||
}
|
||||
|
||||
export type SetSingle = {
|
||||
name: string
|
||||
code: string
|
||||
|
||||
expansionCode?: string
|
||||
tcgoCode?: string
|
||||
|
||||
cardCount: {
|
||||
total: number
|
||||
official: number
|
||||
}
|
||||
|
||||
releaseDate: Date | string
|
||||
|
||||
legal?: {
|
||||
standard: boolean
|
||||
expanded: boolean
|
||||
}
|
||||
|
||||
images?: {
|
||||
symbol?: string
|
||||
logo?: string
|
||||
}
|
||||
|
||||
list: Array<CardSimple>
|
||||
}
|
||||
|
||||
export type SetSimple = {
|
||||
code: string
|
||||
name: string
|
||||
logo?: string
|
||||
symbol?: string
|
||||
total: number
|
||||
}
|
||||
|
||||
export type SetList = List<SetSimple>
|
||||
|
||||
|
||||
export default interface Set {
|
||||
/**
|
||||
* Display Name
|
||||
*/
|
||||
name: LangList<string> | string
|
||||
|
||||
/**
|
||||
* Expansion Object
|
||||
*/
|
||||
expansion?: Expansion
|
||||
|
||||
/**
|
||||
* Expansion code
|
||||
*/
|
||||
expansionCode?: string
|
||||
|
||||
/**
|
||||
* Set code (Also used as the slug)
|
||||
*/
|
||||
code: string
|
||||
|
||||
/**
|
||||
* Trading card online code
|
||||
*/
|
||||
tcgoCode?: string
|
||||
|
||||
cardCount: {
|
||||
/**
|
||||
* total number of cards including secrets
|
||||
*/
|
||||
total: number
|
||||
/**
|
||||
* number of card indicated at the bottom of each cards
|
||||
*/
|
||||
official: number
|
||||
}
|
||||
|
||||
cardTypes?: {
|
||||
/**
|
||||
* Default: true
|
||||
*/
|
||||
normal: boolean
|
||||
/**
|
||||
* Default: true
|
||||
*/
|
||||
reverse: boolean
|
||||
/**
|
||||
* Default: true
|
||||
*/
|
||||
holo: boolean
|
||||
/**
|
||||
* Default: false
|
||||
*/
|
||||
ed1: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Format of numbering
|
||||
* ex: SWSH[000] mean that it has SWSH as prefix and start at 000 -> 001 -> 002 -> etc
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Set
|
||||
*/
|
||||
format?: string
|
||||
|
||||
/**
|
||||
* Release date of the set
|
||||
* in format: yyyy-mm-dd
|
||||
* ex: 2002-12-22
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Set
|
||||
*/
|
||||
releaseDate: string // date in format yyyy-mm-dd
|
||||
|
||||
/**
|
||||
* Aol Endpoint for scrapping
|
||||
*/
|
||||
api?: string
|
||||
|
||||
/**
|
||||
* Competition usage
|
||||
*/
|
||||
legal?: {
|
||||
standard: boolean
|
||||
expanded: boolean
|
||||
}
|
||||
|
||||
images?: {
|
||||
/**
|
||||
* Symbol icon on bottom of card
|
||||
* available extensions [
|
||||
* webp
|
||||
* jpg
|
||||
* png
|
||||
* ]
|
||||
*/
|
||||
symbol?: string
|
||||
/**
|
||||
* Official logo of set
|
||||
* available extensions [
|
||||
* webp
|
||||
* jpg
|
||||
* png
|
||||
* ]
|
||||
*/
|
||||
logo?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Language in which the set is available
|
||||
*/
|
||||
availability?: LangList<boolean>
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
import { List } from "./General"
|
||||
import { CardSimple } from "./Card"
|
||||
/**
|
||||
* Anum of "Tags" each card can contains
|
||||
*
|
||||
* @enum {number}
|
||||
*/
|
||||
enum Tag {
|
||||
/**
|
||||
* basic pokémon
|
||||
*/
|
||||
BASIC,
|
||||
|
||||
/**
|
||||
* Basic Energy
|
||||
*/
|
||||
BASICENERGY,
|
||||
BREAK,
|
||||
EX,
|
||||
GX,
|
||||
ITEM,
|
||||
LEGEND,
|
||||
LEVELUP,
|
||||
MEGA,
|
||||
RESTORED,
|
||||
ROCKETSECRETMACHINE,
|
||||
SP,
|
||||
SPECIAL,
|
||||
STADIUM,
|
||||
/**
|
||||
* Stage 1 pokémon
|
||||
*/
|
||||
STAGE1,
|
||||
|
||||
/**
|
||||
* Stage 2 Pokémon
|
||||
*/
|
||||
STAGE2,
|
||||
SUPPORTER,
|
||||
TAGTEAM,
|
||||
TECHNICALMACHINE,
|
||||
TOOL,
|
||||
|
||||
/**
|
||||
* V Pokémon
|
||||
*/
|
||||
V,
|
||||
|
||||
/**
|
||||
* VMAX Pokémon
|
||||
*/
|
||||
VMAX,
|
||||
|
||||
/**
|
||||
* The card is available with the holographic picture
|
||||
*/
|
||||
HASHOLO,
|
||||
|
||||
/**
|
||||
* Card can have a 1st badge
|
||||
*/
|
||||
HAS1ST,
|
||||
|
||||
/**
|
||||
* Card is full art (art is not in the frame)
|
||||
*/
|
||||
ISFULLART,
|
||||
|
||||
/**
|
||||
* PRIME Pokemon
|
||||
*/
|
||||
PRIME,
|
||||
|
||||
/**
|
||||
* ACE Pokemon
|
||||
*/
|
||||
ACE,
|
||||
|
||||
/**
|
||||
* Card is "rainbow"
|
||||
*/
|
||||
RAINBOW,
|
||||
}
|
||||
|
||||
export default Tag
|
||||
|
||||
export interface TagSimple {
|
||||
id: Tag
|
||||
name: string
|
||||
}
|
||||
|
||||
export type TagSingle = {
|
||||
id: Tag
|
||||
name: string
|
||||
cards: Array<CardSimple>
|
||||
}
|
||||
|
||||
export type TagList = List<TagSimple>
|
@ -1,31 +0,0 @@
|
||||
import { List } from "./General"
|
||||
import { CardSimple } from "./Card"
|
||||
|
||||
enum Type {
|
||||
COLORLESS,
|
||||
DARKNESS,
|
||||
DRAGON,
|
||||
FAIRY,
|
||||
FIGHTING,
|
||||
FIRE,
|
||||
GRASS,
|
||||
LIGHTNING,
|
||||
METAL,
|
||||
PSYCHIC,
|
||||
WATER,
|
||||
}
|
||||
|
||||
export interface TypeSimple {
|
||||
id: Type
|
||||
name: string
|
||||
}
|
||||
|
||||
export type TypeSingle = {
|
||||
id: Type
|
||||
name: string
|
||||
cards: Array<CardSimple>
|
||||
}
|
||||
|
||||
export type TypeList = List<TypeSimple>
|
||||
|
||||
export default Type
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tcgdex/sdk",
|
||||
"version": "1.8.0",
|
||||
"version": "2.0.0-alpha.1",
|
||||
"main": "./tcgdex.js",
|
||||
"types": "./tcgdex.d.ts",
|
||||
"repository": "https://github.com/tcgdex/javascript-sdk.git",
|
||||
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"extends": [
|
||||
"config:base"
|
||||
]
|
||||
}
|
59
tcgdex.ts
59
tcgdex.ts
@ -1,16 +1,10 @@
|
||||
import { SetSingle, SetSimple, SetList, SetSingleRaw } from './interfaces/Set'
|
||||
import { CardSingle, CardList, CardSimple } from './interfaces/Card'
|
||||
import { ExpansionSingle, ExpansionList } from './interfaces/Expansion'
|
||||
import RequestWrapper from './Request'
|
||||
import { Langs } from './interfaces/LangList'
|
||||
import { Serie, Set, Card, CardResume, SerieList, SetList, SupportedLanguages } from './interfaces'
|
||||
|
||||
export default class TCGdex {
|
||||
public static defaultLang: Langs = "en"
|
||||
public lang?: Langs
|
||||
public static defaultLang: SupportedLanguages = "en"
|
||||
|
||||
public constructor(lang?: Langs) {
|
||||
if (lang) this.lang = lang
|
||||
}
|
||||
public constructor(public lang?: SupportedLanguages) {}
|
||||
|
||||
public getLang() {
|
||||
return this.lang || TCGdex.defaultLang
|
||||
@ -18,78 +12,73 @@ export default class TCGdex {
|
||||
|
||||
|
||||
private getBaseUrl() {
|
||||
return `https://api.tcgdex.net/v1/${this.getLang()}`
|
||||
return `https://api.tcgdex.net/v2/${this.getLang()}`
|
||||
}
|
||||
|
||||
private gbu() {
|
||||
return this.getBaseUrl()
|
||||
}
|
||||
|
||||
public async getCard(id: string|number, set: string): Promise<CardSingle | undefined>
|
||||
public async getCard(id: string): Promise<CardSingle | undefined>
|
||||
public async getCard(id: string|number, set?: string): Promise<CardSingle | undefined> {
|
||||
public async getCard(id: string|number, full: true, set?: string): Promise<Card<Set> | undefined>
|
||||
// @ts-expect-error Temporary while building it in the compiler
|
||||
public async getCard(id: string|number, full?: boolean, set?: string): Promise<Card | undefined> {
|
||||
const txt = set ? `sets/${set}` : "cards"
|
||||
const req = this.rwgr<CardSingle>(`${this.gbu()}/${txt}/${id}/`)
|
||||
const req = this.rwgr<Card>(`${this.gbu()}/${txt}/${id}/`)
|
||||
return req.get()
|
||||
}
|
||||
|
||||
public async getCards(set?: string): Promise<Array<CardSimple> | undefined> {
|
||||
public async getCards(set?: string): Promise<Array<CardResume> | undefined> {
|
||||
if (set) {
|
||||
const setSingle = await this.getSet(set)
|
||||
if (!setSingle) {
|
||||
return undefined
|
||||
}
|
||||
return setSingle.list
|
||||
return setSingle.cards
|
||||
}
|
||||
const req = this.rwgr<CardList>(`${this.gbu()}/cards/`)
|
||||
const req = this.rwgr<Array<CardResume>>(`/cards/`)
|
||||
const resp = await req.get()
|
||||
if (!resp) {
|
||||
return undefined
|
||||
}
|
||||
return resp.list
|
||||
return resp
|
||||
}
|
||||
|
||||
public async getSet(set: string, transformDate: false): Promise<SetSingleRaw | undefined>
|
||||
public async getSet(set: string, transformDate?: true): Promise<SetSingle | undefined>
|
||||
public async getSet(set: string, transformDate?: boolean): Promise<SetSingle | SetSingleRaw | undefined> {
|
||||
const req = this.rwgr<SetSingle>(`${this.gbu()}/sets/${set}/`)
|
||||
public async getSet(set: string): Promise<Set | undefined> {
|
||||
const req = this.rwgr<Set>(`/sets/${set}/`)
|
||||
const resp = await req.get()
|
||||
if (!resp) {
|
||||
return undefined
|
||||
}
|
||||
if (!transformDate) {
|
||||
return resp as SetSingleRaw
|
||||
}
|
||||
return Object.assign(resp, {releaseDate: new Date(resp.releaseDate)}) as SetSingle
|
||||
return resp
|
||||
}
|
||||
|
||||
public async getExpansion(expansion: string): Promise<ExpansionSingle | undefined> {
|
||||
const req = this.rwgr<ExpansionSingle>(`${this.gbu()}/expansions/${expansion}/`)
|
||||
public async getSerie(expansion: string): Promise<Serie | undefined> {
|
||||
const req = this.rwgr<Serie>(`/expansions/${expansion}/`)
|
||||
return req.get()
|
||||
}
|
||||
|
||||
public async getExpansions(): Promise<ExpansionList | undefined> {
|
||||
const req = this.rwgr<ExpansionList>(`${this.gbu()}/expansions/`)
|
||||
public async getSeries(): Promise<SerieList | undefined> {
|
||||
const req = this.rwgr<SerieList>(`/expansions/`)
|
||||
return req.get()
|
||||
}
|
||||
|
||||
public async getSets(expansion?: string): Promise<Array<SetSimple> | undefined> {
|
||||
public async getSets(expansion?: string): Promise<SetList | undefined> {
|
||||
if (expansion) {
|
||||
const expansionSingle = await this.getExpansion(expansion)
|
||||
const expansionSingle = await this.getSerie(expansion)
|
||||
if (!expansionSingle) {
|
||||
return undefined
|
||||
}
|
||||
return expansionSingle.sets
|
||||
}
|
||||
const req = this.rwgr<SetList>(`${this.gbu()}/sets/`)
|
||||
const req = this.rwgr<SetList>(`/sets/`)
|
||||
const list = await req.get()
|
||||
if (!list) {
|
||||
return undefined
|
||||
}
|
||||
return list.list
|
||||
return list
|
||||
}
|
||||
|
||||
private rwgr<T = any>(url: string) {
|
||||
return RequestWrapper.getRequest<T>(url)
|
||||
return RequestWrapper.getRequest<T>(`${this.gbu()}${url}`)
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"include": ["**/*.ts"],
|
||||
"exclude": ["translations"],
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
|
Loading…
x
Reference in New Issue
Block a user