Compare commits

...

4 Commits

Author SHA1 Message Date
4597476e6b v2.0.0-beta.5 2021-05-03 21:57:12 +02:00
2ac98526a1 Fixed Items with accents not being correctly fetched
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-05-03 21:56:42 +02:00
040cb4508a v2.0.0-beta.4 2021-05-02 15:49:34 +02:00
edbcf7f4da Add new cardCount field to set
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
2021-05-02 15:48:26 +02:00
4 changed files with 47 additions and 12 deletions

View File

@ -4,3 +4,5 @@
tsconfig.json
*.ts
yarn.lock
test.js
test.d.ts

37
interfaces.d.ts vendored
View File

@ -33,8 +33,14 @@ interface SetResume {
logo?: string
symbol?: string
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 +56,33 @@ export interface Set extends SetResume {
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
}

View File

@ -1,6 +1,6 @@
{
"name": "@tcgdex/sdk",
"version": "2.0.0-beta.3",
"version": "2.0.0-beta.5",
"main": "./tcgdex.js",
"types": "./main.d.ts",
"repository": "https://github.com/tcgdex/javascript-sdk.git",

View File

@ -15,8 +15,8 @@ export default class TCGdex {
}
public async fetchCard(id: string | number, set?: string): Promise<Card | undefined> {
const path = `/${set ? `sets/${set}` : 'cards'}/${id}/`
return this.rwgr<Card>(path).get()
const path = set ? ['sets', set] : ['cards']
return this.rwgr<Card>(...path, id).get()
}
public async fetchCards(set?: string): Promise<Array<CardResume> | undefined> {
@ -27,7 +27,7 @@ export default class TCGdex {
}
return setSingle.cards
}
const req = this.rwgr<Array<CardResume>>(`/cards/`)
const req = this.rwgr<Array<CardResume>>('cards')
const resp = await req.get()
if (!resp) {
return undefined
@ -36,7 +36,7 @@ export default class TCGdex {
}
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()
if (!resp) {
return undefined
@ -45,12 +45,12 @@ export default class TCGdex {
}
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()
}
public async fetchSeries(): Promise<SerieList | undefined> {
const req = this.rwgr<SerieList>(`/series/`)
const req = this.rwgr<SerieList>('series')
return req.get()
}
@ -62,7 +62,7 @@ export default class TCGdex {
}
return expansionSingle.sets
}
const req = this.rwgr<SetList>(`/sets/`)
const req = this.rwgr<SetList>('sets')
const list = await req.get()
if (!list) {
return undefined
@ -70,7 +70,7 @@ export default class TCGdex {
return list
}
private rwgr<T = any>(url: string) {
return RequestWrapper.getRequest<T>(`${this.getBaseUrl()}${url}`)
private rwgr<T = any>(...url: Array<string | number>) {
return RequestWrapper.getRequest<T>(`${this.getBaseUrl()}/${url.map((v) => encodeURI(v.toString())).join('/')}`)
}
}