mirror of
https://github.com/tcgdex/javascript-sdk.git
synced 2025-07-13 18:45:09 +00:00
Compare commits
15 Commits
v2.0.0-bet
...
v2.0.3
Author | SHA1 | Date | |
---|---|---|---|
f7010d5f93
|
|||
ed3fbcf5db
|
|||
f62615814d
|
|||
eec10c548a
|
|||
720bc6b43a
|
|||
3557334076
|
|||
a6e2ee60cc
|
|||
22589b0be5
|
|||
81d4447d27
|
|||
d7ba03749d
|
|||
6c5fc609ae
|
|||
4597476e6b
|
|||
2ac98526a1
|
|||
040cb4508a
|
|||
edbcf7f4da
|
@ -4,3 +4,5 @@
|
|||||||
tsconfig.json
|
tsconfig.json
|
||||||
*.ts
|
*.ts
|
||||||
yarn.lock
|
yarn.lock
|
||||||
|
test.js
|
||||||
|
test.d.ts
|
||||||
|
77
interfaces.d.ts
vendored
77
interfaces.d.ts
vendored
@ -18,11 +18,6 @@ interface variants {
|
|||||||
firstEdition?: boolean
|
firstEdition?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Types = 'Colorless' | 'Darkness' | 'Dragon' |
|
|
||||||
'Fairy' | 'Fightning' | 'Fire' |
|
|
||||||
'Grass' | 'Lightning' | 'Metal' |
|
|
||||||
'Psychic' | 'Water'
|
|
||||||
|
|
||||||
export type SetList = Array<SetResume>
|
export type SetList = Array<SetResume>
|
||||||
export type SerieList = Array<SerieResume>
|
export type SerieList = Array<SerieResume>
|
||||||
export type CardList = Array<CardResume>
|
export type CardList = Array<CardResume>
|
||||||
@ -33,8 +28,14 @@ interface SetResume {
|
|||||||
logo?: string
|
logo?: string
|
||||||
symbol?: string
|
symbol?: string
|
||||||
cardCount: {
|
cardCount: {
|
||||||
total: number
|
/**
|
||||||
official: number
|
* total of number of cards
|
||||||
|
*/
|
||||||
|
total: number
|
||||||
|
/**
|
||||||
|
* number of cards officialy (on the bottom of each cards)
|
||||||
|
*/
|
||||||
|
official: number
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,6 +51,33 @@ export interface Set extends SetResume {
|
|||||||
expanded: boolean
|
expanded: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cardCount: {
|
||||||
|
/**
|
||||||
|
* total of number of cards
|
||||||
|
*/
|
||||||
|
total: number
|
||||||
|
/**
|
||||||
|
* number of cards officialy (on the bottom of each cards)
|
||||||
|
*/
|
||||||
|
official: number
|
||||||
|
/**
|
||||||
|
* number of cards having a normal version
|
||||||
|
*/
|
||||||
|
normal: number
|
||||||
|
/**
|
||||||
|
* number of cards having an reverse version
|
||||||
|
*/
|
||||||
|
reverse: number
|
||||||
|
/**
|
||||||
|
* number of cards having an holo version
|
||||||
|
*/
|
||||||
|
holo: number
|
||||||
|
/**
|
||||||
|
* Number of possible cards
|
||||||
|
*/
|
||||||
|
firstEd?: number
|
||||||
|
}
|
||||||
|
|
||||||
cards: CardList
|
cards: CardList
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +109,7 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
|||||||
* - Ultra Rare
|
* - Ultra Rare
|
||||||
* - Secret Rare
|
* - Secret Rare
|
||||||
*/
|
*/
|
||||||
rarity: 'None' | 'Common'| 'Uncommon' | 'Rare' | 'Ultra Rare' | 'Secret Rare'
|
rarity: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Card Category
|
* Card Category
|
||||||
@ -90,7 +118,7 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
|||||||
* - Trainer
|
* - Trainer
|
||||||
* - Energy
|
* - Energy
|
||||||
*/
|
*/
|
||||||
category: 'Pokemon' | 'Trainer' | 'Energy'
|
category: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Card Variants (Override Set Variants)
|
* Card Variants (Override Set Variants)
|
||||||
@ -119,7 +147,7 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
|||||||
/**
|
/**
|
||||||
* Pokemon Types
|
* Pokemon Types
|
||||||
*/
|
*/
|
||||||
types?: Array<Types> // ex for multiple https://www.tcgdex.net/database/ex/ex13/17
|
types?: Array<string> // ex for multiple https://www.tcgdex.net/database/ex/ex13/17
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pokemon Sub Evolution
|
* Pokemon Sub Evolution
|
||||||
@ -155,7 +183,7 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
|||||||
* - Stage2 https://www.tcgdex.net/database/xy/xy9/3
|
* - Stage2 https://www.tcgdex.net/database/xy/xy9/3
|
||||||
* - VMAX https://www.tcgdex.net/database/swsh/swsh1/50
|
* - VMAX https://www.tcgdex.net/database/swsh/swsh1/50
|
||||||
*/
|
*/
|
||||||
stage?: 'Basic' | 'BREAK' | 'LEVEL-UP' | 'MEGA' | 'RESTORED' | 'Stage1' | 'Stage2' | 'VMAX'
|
stage?: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Card Suffix
|
* Card Suffix
|
||||||
@ -168,7 +196,7 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
|||||||
* - SP https://www.tcgdex.net/database/pl/pl1/7
|
* - SP https://www.tcgdex.net/database/pl/pl1/7
|
||||||
* - TAG TEAM-GX https://www.tcgdex.net/database/sm/sm12/226
|
* - TAG TEAM-GX https://www.tcgdex.net/database/sm/sm12/226
|
||||||
*/
|
*/
|
||||||
suffix?: 'EX' | 'GX' | 'V' | 'Legend' | 'Prime' | 'SP' | 'TAG TEAM-GX'
|
suffix?: string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pokemon Held Item
|
* Pokemon Held Item
|
||||||
@ -186,7 +214,7 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
|||||||
* multi abilities ex https://www.tcgdex.net/database/ex/ex15/10
|
* multi abilities ex https://www.tcgdex.net/database/ex/ex15/10
|
||||||
*/
|
*/
|
||||||
abilities?: Array<{
|
abilities?: Array<{
|
||||||
type: 'Pokemon Power' | 'Poke-BODY' | 'Poke-POWER' | 'Ability' | 'Ancient Trait'
|
type: string
|
||||||
name: string
|
name: string
|
||||||
effect: string
|
effect: string
|
||||||
}>
|
}>
|
||||||
@ -195,7 +223,7 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
|||||||
* Pokemon Attacks
|
* Pokemon Attacks
|
||||||
*/
|
*/
|
||||||
attacks?: Array<{
|
attacks?: Array<{
|
||||||
cost?: Array<Types>
|
cost?: Array<string>
|
||||||
name: string
|
name: string
|
||||||
effect?: string
|
effect?: string
|
||||||
damage?: string | number
|
damage?: string | number
|
||||||
@ -205,12 +233,12 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
|||||||
* Pokemon Weaknesses
|
* Pokemon Weaknesses
|
||||||
*/
|
*/
|
||||||
weaknesses?: Array<{
|
weaknesses?: Array<{
|
||||||
type: Types
|
type: string
|
||||||
value?: string
|
value?: string
|
||||||
}>
|
}>
|
||||||
|
|
||||||
resistances?: Array<{
|
resistances?: Array<{
|
||||||
type: Types
|
type: string
|
||||||
value?: string
|
value?: string
|
||||||
}>
|
}>
|
||||||
|
|
||||||
@ -220,18 +248,15 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
|||||||
effect?: string
|
effect?: string
|
||||||
|
|
||||||
// Trainer Only
|
// Trainer Only
|
||||||
trainerType?: 'Supporter' | // https://www.tcgdex.net/database/ex/ex7/83
|
trainerType?: string
|
||||||
'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
|
// Energy Only
|
||||||
energyType?: 'Normal' | // https://www.tcgdex.net/database/ecard/ecard1/160
|
energyType?: string
|
||||||
'Special' // https://www.tcgdex.net/database/ecard/ecard1/158
|
|
||||||
|
/**
|
||||||
|
* Define the rotation mark on cards >= Sword & Shield
|
||||||
|
*/
|
||||||
|
regulationMark?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type StringEndpointList = Array<string>
|
export type StringEndpointList = Array<string>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tcgdex/sdk",
|
"name": "@tcgdex/sdk",
|
||||||
"version": "2.0.0-beta.3",
|
"version": "2.0.3",
|
||||||
"main": "./tcgdex.js",
|
"main": "./tcgdex.js",
|
||||||
"types": "./main.d.ts",
|
"types": "./main.d.ts",
|
||||||
"repository": "https://github.com/tcgdex/javascript-sdk.git",
|
"repository": "https://github.com/tcgdex/javascript-sdk.git",
|
||||||
|
21
tcgdex.ts
21
tcgdex.ts
@ -15,8 +15,8 @@ export default class TCGdex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async fetchCard(id: string | number, set?: string): Promise<Card | undefined> {
|
public async fetchCard(id: string | number, set?: string): Promise<Card | undefined> {
|
||||||
const path = `/${set ? `sets/${set}` : 'cards'}/${id}/`
|
const path = set ? ['sets', set] : ['cards']
|
||||||
return this.rwgr<Card>(path).get()
|
return this.rwgr<Card>(...path, id).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchCards(set?: string): Promise<Array<CardResume> | undefined> {
|
public async fetchCards(set?: string): Promise<Array<CardResume> | undefined> {
|
||||||
@ -27,7 +27,7 @@ export default class TCGdex {
|
|||||||
}
|
}
|
||||||
return setSingle.cards
|
return setSingle.cards
|
||||||
}
|
}
|
||||||
const req = this.rwgr<Array<CardResume>>(`/cards/`)
|
const req = this.rwgr<Array<CardResume>>('cards')
|
||||||
const resp = await req.get()
|
const resp = await req.get()
|
||||||
if (!resp) {
|
if (!resp) {
|
||||||
return undefined
|
return undefined
|
||||||
@ -36,7 +36,7 @@ export default class TCGdex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async fetchSet(set: string): Promise<Set | undefined> {
|
public async fetchSet(set: string): Promise<Set | undefined> {
|
||||||
const req = this.rwgr<Set>(`/sets/${set}/`)
|
const req = this.rwgr<Set>('sets', set)
|
||||||
const resp = await req.get()
|
const resp = await req.get()
|
||||||
if (!resp) {
|
if (!resp) {
|
||||||
return undefined
|
return undefined
|
||||||
@ -45,12 +45,12 @@ export default class TCGdex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async fetchSerie(expansion: string): Promise<Serie | undefined> {
|
public async fetchSerie(expansion: string): Promise<Serie | undefined> {
|
||||||
const req = this.rwgr<Serie>(`/series/${expansion}/`)
|
const req = this.rwgr<Serie>('series', expansion)
|
||||||
return req.get()
|
return req.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchSeries(): Promise<SerieList | undefined> {
|
public async fetchSeries(): Promise<SerieList | undefined> {
|
||||||
const req = this.rwgr<SerieList>(`/series/`)
|
const req = this.rwgr<SerieList>('series')
|
||||||
return req.get()
|
return req.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ export default class TCGdex {
|
|||||||
}
|
}
|
||||||
return expansionSingle.sets
|
return expansionSingle.sets
|
||||||
}
|
}
|
||||||
const req = this.rwgr<SetList>(`/sets/`)
|
const req = this.rwgr<SetList>('sets')
|
||||||
const list = await req.get()
|
const list = await req.get()
|
||||||
if (!list) {
|
if (!list) {
|
||||||
return undefined
|
return undefined
|
||||||
@ -70,7 +70,10 @@ export default class TCGdex {
|
|||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
private rwgr<T = any>(url: string) {
|
private rwgr<T = any>(...url: Array<string | number>) {
|
||||||
return RequestWrapper.getRequest<T>(`${this.getBaseUrl()}${url}`)
|
return RequestWrapper.getRequest<T>(`${this.getBaseUrl()}/${url.map((v) => encodeURI(
|
||||||
|
// Normalize URL
|
||||||
|
v.toString().replace('?', '%3F').normalize('NFC').replace(/["'\u0300-\u036f]/g, "")
|
||||||
|
)).join('/')}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
import { translations } from "../TranslationUtil"
|
|
||||||
|
|
||||||
const translations: translations = {
|
|
||||||
en: [
|
|
||||||
"Poké-Body",
|
|
||||||
"Poké-Power",
|
|
||||||
"Ability",
|
|
||||||
"Ancient Trait"
|
|
||||||
],
|
|
||||||
fr: [
|
|
||||||
"Poké-Body",
|
|
||||||
"Poké-Power",
|
|
||||||
"Talent",
|
|
||||||
"Trait Ancien"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
export default translations
|
|
@ -1,15 +0,0 @@
|
|||||||
import { translations } from "../TranslationUtil"
|
|
||||||
|
|
||||||
const translations: translations = {
|
|
||||||
en: [
|
|
||||||
"Pokémon",
|
|
||||||
"Trainer",
|
|
||||||
"Energy"
|
|
||||||
],
|
|
||||||
fr: [
|
|
||||||
"Pokémon",
|
|
||||||
"Dresseur",
|
|
||||||
"Énergie"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
export default translations
|
|
@ -1,21 +0,0 @@
|
|||||||
import { translations } from "../TranslationUtil"
|
|
||||||
|
|
||||||
const translations: translations = {
|
|
||||||
en: [
|
|
||||||
"No rarity",
|
|
||||||
"Common",
|
|
||||||
"unCommon",
|
|
||||||
"Rare",
|
|
||||||
"Rare Ultra",
|
|
||||||
"Ultra Rare",
|
|
||||||
],
|
|
||||||
fr: [
|
|
||||||
"Sans rareté",
|
|
||||||
"Commun",
|
|
||||||
"Non Commun",
|
|
||||||
"Rare",
|
|
||||||
"Rare Ultra",
|
|
||||||
"Ultra Rare",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
export default translations
|
|
@ -1,59 +0,0 @@
|
|||||||
import { translations } from "../TranslationUtil"
|
|
||||||
|
|
||||||
const translations: translations = {
|
|
||||||
en: [
|
|
||||||
"Basic Pokémon",
|
|
||||||
"Basic Energy",
|
|
||||||
"BREAK",
|
|
||||||
"EX",
|
|
||||||
"GX",
|
|
||||||
"Item",
|
|
||||||
"LEGEND",
|
|
||||||
"Level-Up",
|
|
||||||
"MEGA",
|
|
||||||
"Restored",
|
|
||||||
"Rocket's Secret Machine",
|
|
||||||
"SP",
|
|
||||||
"Special",
|
|
||||||
"Stadium",
|
|
||||||
"Stage 1",
|
|
||||||
"Stage 2",
|
|
||||||
"Supporter",
|
|
||||||
"Tag Team",
|
|
||||||
"Technical Machine",
|
|
||||||
"Tool",
|
|
||||||
"Pokémon V",
|
|
||||||
"Pokémon VMAX",
|
|
||||||
"Prime",
|
|
||||||
"ACE",
|
|
||||||
"Rainbow",
|
|
||||||
],
|
|
||||||
fr: [
|
|
||||||
"Pokémon de base",
|
|
||||||
"Energie de base",
|
|
||||||
"TURBO",
|
|
||||||
"EX",
|
|
||||||
"GX",
|
|
||||||
"Objet",
|
|
||||||
"LÉGENDE",
|
|
||||||
"Niveau Sup",
|
|
||||||
"Méga",
|
|
||||||
"Restauré",
|
|
||||||
"Machine secrète dees Rocket",
|
|
||||||
"SP",
|
|
||||||
"Spéciale",
|
|
||||||
"Stadium",
|
|
||||||
"Niveau 1",
|
|
||||||
"Niveau 2",
|
|
||||||
"Supporter",
|
|
||||||
"ESCOUADE",
|
|
||||||
"Machine Technique",
|
|
||||||
"Outil",
|
|
||||||
"Pokémon V",
|
|
||||||
"Pokémon VMAX",
|
|
||||||
"Prime",
|
|
||||||
"ACE",
|
|
||||||
"Arc en ciel",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
export default translations
|
|
@ -1,32 +0,0 @@
|
|||||||
import { translations } from "../TranslationUtil";
|
|
||||||
|
|
||||||
const trans: translations = {
|
|
||||||
en: [
|
|
||||||
"Colorless",
|
|
||||||
"Darkness",
|
|
||||||
"Dragon",
|
|
||||||
"Fairy",
|
|
||||||
"Fighting",
|
|
||||||
"Fire",
|
|
||||||
"Grass",
|
|
||||||
"Lightning",
|
|
||||||
"Metal",
|
|
||||||
"Psychic",
|
|
||||||
"Water"
|
|
||||||
],
|
|
||||||
fr: [
|
|
||||||
"Incolore",
|
|
||||||
"Obscurité",
|
|
||||||
"Dragon",
|
|
||||||
"Fée",
|
|
||||||
"Combat",
|
|
||||||
"Feu",
|
|
||||||
"Plante",
|
|
||||||
"Électrique",
|
|
||||||
"Métal",
|
|
||||||
"Psy",
|
|
||||||
"Eau"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
export default trans
|
|
Reference in New Issue
Block a user