mirror of
https://github.com/tcgdex/javascript-sdk.git
synced 2025-07-13 18:45:09 +00:00
Compare commits
7 Commits
1.0.7
...
1.2.0-beta
Author | SHA1 | Date | |
---|---|---|---|
a886302e05 | |||
75bc7249f1 | |||
00316364fa | |||
3cdc149845 | |||
d0088d62cb | |||
405cd8542a | |||
53afc67b72 |
@ -14,7 +14,7 @@ export default class TranslationUtil {
|
||||
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 {
|
||||
const trans = require(`./${master}`).default as translations
|
||||
const trans = require(`./translations/${master}`).default as translations
|
||||
const tmp = trans[lang]
|
||||
if (!tmp) return
|
||||
return tmp[a]
|
||||
|
@ -3,6 +3,12 @@ export interface AbilityTypeSimple {
|
||||
name: string
|
||||
}
|
||||
|
||||
export type AbilityTypeSingle = {
|
||||
id: AbilityType
|
||||
name: string
|
||||
cards: string
|
||||
}
|
||||
|
||||
enum AbilityType {
|
||||
POKEBODY,
|
||||
POKEPOWER,
|
||||
|
@ -11,6 +11,7 @@ import Set from "./Set";
|
||||
|
||||
export interface CardSimple {
|
||||
id: string
|
||||
localId: string|number
|
||||
name: string
|
||||
image: string
|
||||
}
|
||||
@ -33,10 +34,34 @@ export interface CardSingle {
|
||||
code: string
|
||||
}
|
||||
cardTypes?: {
|
||||
normal: boolean
|
||||
reverse: boolean
|
||||
holo: boolean
|
||||
firstEd: boolean
|
||||
/**
|
||||
* normal card without anything special
|
||||
*
|
||||
*
|
||||
* @type {boolean} consider `undefined` to true
|
||||
*/
|
||||
normal?: boolean
|
||||
/**
|
||||
* Card which has a holographic background
|
||||
* but not the picture
|
||||
*
|
||||
* @type {boolean} `undefined` === `true`
|
||||
*/
|
||||
reverse?: boolean
|
||||
/**
|
||||
* Card which has a hologaphic picture
|
||||
*
|
||||
* @type {boolean} `undefined` === `false`
|
||||
*/
|
||||
holo?: boolean
|
||||
/**
|
||||
* Card which can have a `1st ed` icon
|
||||
*
|
||||
* only the base expansion should received it
|
||||
*
|
||||
* @type {boolean} `undefined` === `false`
|
||||
*/
|
||||
firstEd?: boolean
|
||||
}
|
||||
|
||||
// Pokémon only
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { CardSimple } from "./Card";
|
||||
import { List } from "./General";
|
||||
|
||||
export type IllustratorSingle = {
|
||||
id: number,
|
||||
@ -11,10 +12,7 @@ export interface IllustratorSimple {
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface IllustratorsList {
|
||||
count: number
|
||||
list: Array<IllustratorSimple>
|
||||
}
|
||||
export type IllustratorsList = List<IllustratorSimple>
|
||||
|
||||
interface Illustrator {
|
||||
id: number
|
||||
|
@ -1,3 +1,6 @@
|
||||
import { List } from "./General"
|
||||
import { CardSimple } from "./Card"
|
||||
|
||||
export enum Rarity {
|
||||
Common,
|
||||
Uncommon,
|
||||
@ -30,3 +33,11 @@ export interface RaritySimple {
|
||||
id: Rarity
|
||||
name: string
|
||||
}
|
||||
|
||||
export type RaritySingle = {
|
||||
id: Rarity
|
||||
name: string
|
||||
cards: Array<CardSimple>
|
||||
}
|
||||
|
||||
export type RarityList = List<RaritySimple>
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { CardSimple } from "./Card";
|
||||
import { List } from "./General";
|
||||
|
||||
export type RetreatSimple = number
|
||||
|
||||
@ -7,7 +8,4 @@ export interface RetreatSingle {
|
||||
cards: Array<CardSimple>
|
||||
}
|
||||
|
||||
export interface RetreatList {
|
||||
count: number,
|
||||
list: Array<RetreatSimple>
|
||||
}
|
||||
export type RetreatList = List<RetreatSimple>
|
||||
|
@ -36,6 +36,8 @@ export type SetSingle = {
|
||||
export type SetSimple = {
|
||||
code: string
|
||||
name: string
|
||||
logo?: string
|
||||
symbol?: string
|
||||
total: number
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
import { List } from "./General"
|
||||
import { CardSimple } from "./Card"
|
||||
|
||||
enum Tag {
|
||||
BASIC,
|
||||
BASICENERGY,
|
||||
@ -29,3 +32,11 @@ export interface TagSimple {
|
||||
id: Tag
|
||||
name: string
|
||||
}
|
||||
|
||||
export type TagSingle = {
|
||||
id: Tag
|
||||
name: string
|
||||
cards: Array<CardSimple>
|
||||
}
|
||||
|
||||
export type TagList = List<TagSimple>
|
||||
|
@ -1,3 +1,6 @@
|
||||
import { List } from "./General"
|
||||
import { CardSimple } from "./Card"
|
||||
|
||||
enum Type {
|
||||
COLORLESS,
|
||||
DARKNESS,
|
||||
@ -17,4 +20,12 @@ export interface TypeSimple {
|
||||
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.0.7",
|
||||
"version": "1.2.0-beta.1",
|
||||
"main": "./tcgdex.js",
|
||||
"types": "./types/tcgdex.d.ts",
|
||||
"repository": "https://git.delta-wings.net/tcgdex/javascript-sdk.git",
|
||||
|
75
tcgdex.ts
75
tcgdex.ts
@ -1,8 +1,8 @@
|
||||
import fetch from 'isomorphic-unfetch'
|
||||
import { Langs } from './interfaces/Langs'
|
||||
import { SetSingle, SetRequest } from './interfaces/Set'
|
||||
import { SetSingle, SetRequest, SetSimple } from './interfaces/Set'
|
||||
import { CardSingle } from './interfaces/Card'
|
||||
import { ExpansionSingle } from './interfaces/Expansion'
|
||||
import { ExpansionSingle, ExpansionList } from './interfaces/Expansion'
|
||||
|
||||
export default class TCGdex {
|
||||
public lang: Langs = "en"
|
||||
@ -24,7 +24,7 @@ export default class TCGdex {
|
||||
public async getCard(id: string|number, set?: string): Promise<CardSingle> {
|
||||
try {
|
||||
const txt = set ? `sets/${set}` : "cards"
|
||||
const resp = await fetch(`${this.gbu()}/${txt}/${id}`)
|
||||
const resp = await fetch(`${this.gbu()}/${txt}/${id}/`)
|
||||
if (resp.status !== 200) throw new Error("Card not found")
|
||||
try {
|
||||
return await resp.json()
|
||||
@ -36,9 +36,34 @@ export default class TCGdex {
|
||||
}
|
||||
}
|
||||
|
||||
public async getCards(set?: string) {
|
||||
if (set) {
|
||||
try {
|
||||
const setSingle = await this.getSet(set)
|
||||
return setSingle.list
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
try {
|
||||
console.warn("note: while it's possible to fetch every cards at once it's not recommended as it take much more time than any other requests")
|
||||
const resp = await fetch(`${this.gbu()}/cards/`)
|
||||
if (resp.status !== 200) {
|
||||
throw new Error("Could not fetch cards")
|
||||
}
|
||||
try {
|
||||
return resp.json()
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
public async getSet(set: string): Promise<SetSingle> {
|
||||
try {
|
||||
const resp = await fetch(`${this.gbu()}/sets/${set}`)
|
||||
const resp = await fetch(`${this.gbu()}/sets/${set}/`)
|
||||
console.log(resp.status)
|
||||
if (resp.status !== 200) throw new Error("Set not found")
|
||||
try {
|
||||
@ -54,7 +79,7 @@ export default class TCGdex {
|
||||
|
||||
public async getExpansion(expansion: string): Promise<ExpansionSingle> {
|
||||
try {
|
||||
const resp = await fetch(`${this.gbu()}/expansions/${expansion}`)
|
||||
const resp = await fetch(`${this.gbu()}/expansions/${expansion}/`)
|
||||
if (resp.status !== 200) throw new Error("Expansion not found")
|
||||
try {
|
||||
return await resp.json()
|
||||
@ -65,4 +90,44 @@ export default class TCGdex {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
public async getExpansions(): Promise<ExpansionList> {
|
||||
try {
|
||||
const resp = await fetch(`${this.gbu()}/expansions/`)
|
||||
if (resp.status !== 200) throw new Error("Could not fetch expansions")
|
||||
try {
|
||||
return await resp.json()
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
public async getSets(expansion?: string): Promise<Array<SetSimple>> {
|
||||
if (expansion) {
|
||||
try {
|
||||
const expansionSingle = await this.getExpansion(expansion)
|
||||
return expansionSingle.sets
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
const resp = await fetch(`${this.gbu()}/sets/`)
|
||||
if (resp.status !== 200) {
|
||||
throw new Error("Could not fetch sets")
|
||||
}
|
||||
try {
|
||||
return resp.json()
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user