mirror of
https://github.com/tcgdex/javascript-sdk.git
synced 2025-07-13 10:35:11 +00:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
f1f4ef3d94 | |||
5315c9511d | |||
561ec85545 | |||
f7044c7b10 |
46
README.md
46
README.md
@ -1,8 +1,44 @@
|
|||||||
current endpoints
|
# TCGdex Javacript SDK
|
||||||
|
|
||||||
```js
|
## Install
|
||||||
console.log(await tcgdex.getCard("1", "hgss1"))
|
|
||||||
console.log(await tcgdex.getSet("hgss1"))
|
|
||||||
console.log(await tcgdex.getExpansion("hgss"))
|
|
||||||
|
|
||||||
|
### Yarn/npm
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yarn add @tcgdex/sdk
|
||||||
|
```
|
||||||
|
or with npm
|
||||||
|
```bash
|
||||||
|
npm install @tcgdex/sdk
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
_Note: a complete documentation is in progress_
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import TCGdex from '@tcgdex/sdk'
|
||||||
|
import TranslationUtil from '@tcgdex/sdk/TranslationUtil'
|
||||||
|
import Tag from '@tcgdex/sdk/interfaces/Tag'
|
||||||
|
|
||||||
|
// init the class
|
||||||
|
const tcgdex = new TCGdex("en") // Lang code (Optionnal) (See TranslationUtil.ts line 3)
|
||||||
|
|
||||||
|
// change lang
|
||||||
|
tcgdex.lang = "fr"
|
||||||
|
|
||||||
|
// get Card object wih global id
|
||||||
|
await tcgdex.getCard("base1-1")
|
||||||
|
|
||||||
|
// get Card object with local id and set
|
||||||
|
await tcgdex.getCard(1, "base1")
|
||||||
|
|
||||||
|
// get Set informations
|
||||||
|
await tcgdex.getSet("base1")
|
||||||
|
|
||||||
|
// get Expansion
|
||||||
|
await tcgdex.getExpansion("base")
|
||||||
|
|
||||||
|
// Translate information from code to the lang
|
||||||
|
TranslationUtil.translate("tag", Tag.STAGE2, "en")
|
||||||
```
|
```
|
||||||
|
@ -1,8 +1,18 @@
|
|||||||
import LangList, { Langs } from "./interfaces/LangList";
|
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";
|
||||||
|
|
||||||
type possibilities = "abilityType" | "category" | "rarity" | "tag" | "type"
|
type possibilities = "abilityType" | "category" | "rarity" | "tag" | "type"
|
||||||
|
|
||||||
export default class TranslationUtil {
|
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 {
|
public static translate(master: possibilities,a: number, lang: Langs): string|undefined {
|
||||||
const trans = require(`./${master}`).default as translations
|
const trans = require(`./${master}`).default as translations
|
||||||
const tmp = trans[lang]
|
const tmp = trans[lang]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tcgdex/sdk",
|
"name": "@tcgdex/sdk",
|
||||||
"version": "1.0.5",
|
"version": "1.0.6",
|
||||||
"main": "./tcgdex.js",
|
"main": "./tcgdex.js",
|
||||||
"types": "./types/tcgdex.d.ts",
|
"types": "./types/tcgdex.d.ts",
|
||||||
"repository": "https://git.delta-wings.net/tcgdex/javascript-sdk.git",
|
"repository": "https://git.delta-wings.net/tcgdex/javascript-sdk.git",
|
||||||
|
@ -4,8 +4,8 @@ import { SetSingle, SetRequest } from './interfaces/Set'
|
|||||||
import { CardSingle } from './interfaces/Card'
|
import { CardSingle } from './interfaces/Card'
|
||||||
import { ExpansionSingle } from './interfaces/Expansion'
|
import { ExpansionSingle } from './interfaces/Expansion'
|
||||||
|
|
||||||
export default class TCGDex {
|
export default class TCGdex {
|
||||||
private lang: Langs = "en"
|
public lang: Langs = "en"
|
||||||
|
|
||||||
public constructor(lang?: Langs) {
|
public constructor(lang?: Langs) {
|
||||||
if (lang) this.lang = lang
|
if (lang) this.lang = lang
|
||||||
@ -19,7 +19,9 @@ export default class TCGDex {
|
|||||||
return this.getBaseUrl()
|
return this.getBaseUrl()
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getCard(id: string, set?: string): Promise<CardSingle> {
|
public async getCard(id: string|number, set: string): Promise<CardSingle>;
|
||||||
|
public async getCard(id: string): Promise<CardSingle>;
|
||||||
|
public async getCard(id: string|number, set?: string): Promise<CardSingle> {
|
||||||
try {
|
try {
|
||||||
const txt = set ? `sets/${set}` : "cards"
|
const txt = set ? `sets/${set}` : "cards"
|
||||||
const resp = await fetch(`${this.gbu()}/${txt}/${id}`)
|
const resp = await fetch(`${this.gbu()}/${txt}/${id}`)
|
||||||
|
Reference in New Issue
Block a user