So I was looking through your code and was hoping you an explain some things.
For example you do not have exposed the catalogs api, so I think this would work, but I am not sure.
// src/scryfall.ts
//...
import { ScryfallCatalog } from "./ScryfallCatalog";
//...
/**
* The list of all known catalogs currated by Scryfall itself. Currently there
* is no endpoint (e.g. api.scryfall.com/catalogs), which returns what catalogs
* exists.
* Each entry in this list is the trailing slug of https://api.scryfall.com/catalog/
*/
const knownCatalogs = [
'card-names',
'artist-names',
'word-bank',
'creature-types',
'planeswalker-types',
'land-types',
'artifact-types',
'enchantment-types',
'spell-types',
'powers',
'toughnesses',
'loyalties',
'watermarks',
]
/**
* Attempts to fetch the catalog of the given name, returning the list of its entries
* @param name The name of the catalog to fetch
* @returns A promise, if no callback is specified. Otherwise nothing.
*/
export function getCatalog(
name: string,
cb: (res: ScryfallCatalog) => void,
): Promise<ScryfallCatalog> {
const ret = (res, rej) => {
const isValid = !(knownCatalogs.indexOf(name.toLowerCase().replaced(' ', '-')) < 0)
const err = new Error(`${name} is not a known catalog`);
if (!isValid) rej(err)
APIRequest(`/catalog/${name}`, (catalog: ScryfallError | ScryfallCatalog) => {
if (catalog.object === "error") {
rej ? rej(catalog) : res(catalog);
} else {
rej ? res(catalog) : res(null, catalog);
}
});
}
if (cb) {
ret(cb, null);
} else {
return new Promise<ScryfallCatalog>((resolve, reject) => ret(resolve, reject));
}
}
basically I am not the most familiar with typescript... and also I am not so sure what your callback is doing?
So I was looking through your code and was hoping you an explain some things.
For example you do not have exposed the catalogs api, so I think this would work, but I am not sure.
basically I am not the most familiar with typescript... and also I am not so sure what your callback is doing?