From 2ac98526a110550472cff5f35c7ce0e86f8ef07c Mon Sep 17 00:00:00 2001 From: Avior Date: Mon, 3 May 2021 21:56:42 +0200 Subject: [PATCH] Fixed Items with accents not being correctly fetched Signed-off-by: Avior --- .npmignore | 2 ++ tcgdex.ts | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.npmignore b/.npmignore index 3cc73c0..de11e19 100644 --- a/.npmignore +++ b/.npmignore @@ -4,3 +4,5 @@ tsconfig.json *.ts yarn.lock +test.js +test.d.ts diff --git a/tcgdex.ts b/tcgdex.ts index ea2a87e..c436582 100644 --- a/tcgdex.ts +++ b/tcgdex.ts @@ -15,8 +15,8 @@ export default class TCGdex { } public async fetchCard(id: string | number, set?: string): Promise { - const path = `/${set ? `sets/${set}` : 'cards'}/${id}/` - return this.rwgr(path).get() + const path = set ? ['sets', set] : ['cards'] + return this.rwgr(...path, id).get() } public async fetchCards(set?: string): Promise | undefined> { @@ -27,7 +27,7 @@ export default class TCGdex { } return setSingle.cards } - const req = this.rwgr>(`/cards/`) + const req = this.rwgr>('cards') const resp = await req.get() if (!resp) { return undefined @@ -36,7 +36,7 @@ export default class TCGdex { } public async fetchSet(set: string): Promise { - const req = this.rwgr(`/sets/${set}/`) + const req = this.rwgr('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 { - const req = this.rwgr(`/series/${expansion}/`) + const req = this.rwgr('series', expansion) return req.get() } public async fetchSeries(): Promise { - const req = this.rwgr(`/series/`) + const req = this.rwgr('series') return req.get() } @@ -62,7 +62,7 @@ export default class TCGdex { } return expansionSingle.sets } - const req = this.rwgr(`/sets/`) + const req = this.rwgr('sets') const list = await req.get() if (!list) { return undefined @@ -70,7 +70,7 @@ export default class TCGdex { return list } - private rwgr(url: string) { - return RequestWrapper.getRequest(`${this.getBaseUrl()}${url}`) + private rwgr(...url: Array) { + return RequestWrapper.getRequest(`${this.getBaseUrl()}/${url.map((v) => encodeURI(v.toString())).join('/')}`) } }