mirror of
https://github.com/tcgdex/compiler.git
synced 2025-07-29 07:29:50 +00:00
Add eslint (#12)
* Done ! Signed-off-by: Florian BOUILLON <florian.bouillon@delta-wings.net> * ACT doesn't wanna work so I push Signed-off-by: Florian BOUILLON <florian.bouillon@delta-wings.net> * Continued work on ESLint Signed-off-by: Florian BOUILLON <florian.bouillon@delta-wings.net> * Two files remaining Signed-off-by: Avior <github@avior.me> * Fixed set cards not found when using ids Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
@ -1,12 +1,22 @@
|
||||
import { setToSetSimple } from "./setUtil"
|
||||
import { cardIsLegal, fetchRemoteFile, smartGlob } from "./util"
|
||||
/* eslint-disable sort-keys */
|
||||
import { setToSetSimple } from './setUtil'
|
||||
import { cardIsLegal, fetchRemoteFile, smartGlob } from './util'
|
||||
import { Set, SupportedLanguages, Card, Types } from 'db/interfaces'
|
||||
import { Card as CardSingle, CardResume } from '@tcgdex/sdk/interfaces'
|
||||
import translate from './translationUtil'
|
||||
|
||||
type ObjectList<T = any> = Partial<Record<string, T>>
|
||||
|
||||
type RemoteData = ObjectList<ObjectList<ObjectList<ObjectList<string>>>>
|
||||
export async function getCardPictures(cardId: string, card: Card, lang: SupportedLanguages): Promise<string | undefined> {
|
||||
try {
|
||||
const file = await fetchRemoteFile('https://assets.tcgdex.net/datas.json')
|
||||
const fileExists = Boolean(file[lang]?.[card.set.serie.id]?.[card.set.id]?.[cardId])
|
||||
if (fileExists) {
|
||||
return `https://assets.tcgdex.net/${lang}/${card.set.serie.id}/${card.set.id}/${cardId}`
|
||||
}
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
export async function cardToCardSimple(id: string, card: Card, lang: SupportedLanguages): Promise<CardResume> {
|
||||
const cardName = card.name[lang]
|
||||
@ -16,26 +26,14 @@ export async function cardToCardSimple(id: string, card: Card, lang: SupportedLa
|
||||
const img = await getCardPictures(id, card, lang)
|
||||
return {
|
||||
id: `${card.set.id}-${id}`,
|
||||
image: img,
|
||||
localId: id,
|
||||
name: cardName,
|
||||
image: img
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCardPictures(cardId: string, card: Card, lang: SupportedLanguages): Promise<string | undefined> {
|
||||
try {
|
||||
const file = await fetchRemoteFile(`https://assets.tcgdex.net/datas.json`)
|
||||
const fileExists = !!file[lang]?.[card.set.serie.id]?.[card.set.id]?.[cardId]
|
||||
if (fileExists) {
|
||||
return `https://assets.tcgdex.net/${lang}/${card.set.serie.id}/${card.set.id}/${cardId}`
|
||||
}
|
||||
} catch {
|
||||
return undefined
|
||||
name: cardName
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line max-lines-per-function
|
||||
export async function cardToCardSingle(localId: string, card: Card, lang: SupportedLanguages): Promise<CardSingle> {
|
||||
|
||||
const image = await getCardPictures(localId, card, lang)
|
||||
|
||||
if (!card.name[lang]) {
|
||||
@ -43,22 +41,22 @@ export async function cardToCardSingle(localId: string, card: Card, lang: Suppor
|
||||
}
|
||||
|
||||
return {
|
||||
id: `${card.set.id}-${localId}`,
|
||||
localId: localId,
|
||||
name: card.name[lang] as string,
|
||||
image: image,
|
||||
|
||||
illustrator: card.illustrator,
|
||||
rarity: translate('rarity', card.rarity, lang) as any,
|
||||
category: translate('category', card.category, lang) as any,
|
||||
id: `${card.set.id}-${localId}`,
|
||||
illustrator: card.illustrator,
|
||||
image,
|
||||
localId,
|
||||
name: card.name[lang] as string,
|
||||
|
||||
rarity: translate('rarity', card.rarity, lang) as any,
|
||||
set: await setToSetSimple(card.set, lang),
|
||||
variants: {
|
||||
normal: typeof card.variants?.normal === 'boolean' ? card.variants.normal : typeof card.set.variants?.normal === 'boolean' ? card.set.variants.normal : true,
|
||||
reverse: typeof card.variants?.reverse === 'boolean' ? card.variants.reverse : typeof card.set.variants?.reverse === 'boolean' ? card.set.variants.reverse : true,
|
||||
holo: typeof card.variants?.holo === 'boolean' ? card.variants.holo : typeof card.set.variants?.holo === 'boolean' ? card.set.variants.holo : true,
|
||||
firstEdition: typeof card.variants?.firstEdition === 'boolean' ? card.variants.firstEdition : typeof card.set.variants?.firstEdition === 'boolean' ? card.set.variants.firstEdition : false,
|
||||
holo: typeof card.variants?.holo === 'boolean' ? card.variants.holo : typeof card.set.variants?.holo === 'boolean' ? card.set.variants.holo : true,
|
||||
normal: typeof card.variants?.normal === 'boolean' ? card.variants.normal : typeof card.set.variants?.normal === 'boolean' ? card.set.variants.normal : true,
|
||||
reverse: typeof card.variants?.reverse === 'boolean' ? card.variants.reverse : typeof card.set.variants?.reverse === 'boolean' ? card.set.variants.reverse : true
|
||||
},
|
||||
|
||||
set: await setToSetSimple(card.set, lang),
|
||||
|
||||
dexId: card.dexId,
|
||||
hp: card.hp,
|
||||
@ -86,7 +84,6 @@ export async function cardToCardSingle(localId: string, card: Card, lang: Suppor
|
||||
effect: el.effect ? el.effect[lang] : undefined,
|
||||
damage: el.damage
|
||||
})),
|
||||
|
||||
weaknesses: card.weaknesses?.map((el) => ({
|
||||
type: translate('types', el.type, lang) as Types,
|
||||
value: el.value
|
||||
@ -124,7 +121,7 @@ export async function getCard(serie: string, setName: string, id: string): Promi
|
||||
}
|
||||
|
||||
export async function getCards(lang: SupportedLanguages, set?: Set): Promise<Array<[string, Card]>> {
|
||||
const cards = (await smartGlob(`./db/data/${(set && set.serie.name.en) ?? '*'}/${(set && set.name.en) ?? '*'}/*.js`))
|
||||
const cards = await smartGlob(`./db/data/${(set && set.serie.name.en) ?? '*'}/${(set && set.name.en) ?? '*'}/*.js`)
|
||||
const list: Array<[string, Card]> = []
|
||||
for (const path of cards) {
|
||||
const id = path.substring(path.lastIndexOf('/') + 1, path.lastIndexOf('.'))
|
||||
@ -146,12 +143,11 @@ export async function getCards(lang: SupportedLanguages, set?: Set): Promise<Arr
|
||||
|
||||
// Sort by id when possible
|
||||
return list.sort(([a], [b]) => {
|
||||
const ra = parseInt(a)
|
||||
const rb = parseInt(b)
|
||||
const ra = parseInt(a, 10)
|
||||
const rb = parseInt(b, 10)
|
||||
if (!isNaN(ra) && !isNaN(rb)) {
|
||||
return ra - rb
|
||||
} else {
|
||||
return a >= b ? 1 : -1
|
||||
}
|
||||
return a >= b ? 1 : -1
|
||||
})
|
||||
}
|
||||
|
@ -1,44 +1,43 @@
|
||||
import { smartGlob } from "./util"
|
||||
import { setToSetSimple, getSets, getSet, isSetAvailable } from "./setUtil"
|
||||
import { smartGlob } from './util'
|
||||
import { setToSetSimple, getSets } from './setUtil'
|
||||
import { Serie, SupportedLanguages, Set } from 'db/interfaces'
|
||||
import { Serie as SerieSingle, SerieResume } from '@tcgdex/sdk/interfaces'
|
||||
|
||||
export async function getSerie(name: string): Promise<Serie> {
|
||||
return (await import(`../db/data/${name}.js`)).default
|
||||
}
|
||||
|
||||
export async function isSerieAvailable(serie: Serie, lang: SupportedLanguages): Promise<boolean> {
|
||||
if (!serie.name[lang]) {
|
||||
return false
|
||||
}
|
||||
const sets = await getSets(serie.name.en, lang)
|
||||
return sets.length > 0
|
||||
}
|
||||
|
||||
export async function getSeries(lang: SupportedLanguages): Promise<Array<Serie>> {
|
||||
let series: Array<Serie> = (await Promise.all((await smartGlob('./db/data/*.js'))
|
||||
//Find Serie's name
|
||||
// Find Serie's name
|
||||
.map((it) => it.substring(it.lastIndexOf('/') + 1, it.length - 3))
|
||||
// Fetch the Serie
|
||||
.map((it) => getSerie(it))))
|
||||
// Filter the serie if no name's exists in the selected lang
|
||||
.filter((serie) => !!serie.name[lang])
|
||||
.filter((serie) => Boolean(serie.name[lang]))
|
||||
|
||||
// Filter available series
|
||||
const isAvailable = await Promise.all(series.map((serie) => isSerieAvailable(serie, lang)))
|
||||
series = series.filter((_, index) => isAvailable[index])
|
||||
|
||||
// Sort series by the first set release date
|
||||
const tmp: Array<[Serie, Set | undefined]> = await Promise.all(series.map(async (it) => {
|
||||
return [
|
||||
it,
|
||||
(await getSets(it.name.en, lang))
|
||||
.reduce<Set | undefined>((p, c) => p ? p.releaseDate < c.releaseDate ? p : c : c, undefined) as Set] as [Serie, Set]
|
||||
}))
|
||||
const tmp: Array<[Serie, Set | undefined]> = await Promise.all(series.map(async (it) => [
|
||||
it,
|
||||
(await getSets(it.name.en, lang))
|
||||
.reduce<Set | undefined>((p, c) => p ? p.releaseDate < c.releaseDate ? p : c : c, undefined) as Set
|
||||
] as [Serie, Set]))
|
||||
|
||||
return tmp.sort((a, b) => (a[1] ? a[1].releaseDate : '0') > (b[1] ? b[1].releaseDate : '0') ? 1 : -1).map((it) => it[0])
|
||||
}
|
||||
|
||||
export async function getSerie(name: string): Promise<Serie> {
|
||||
return (await import(`../db/data/${name}.js`)).default
|
||||
}
|
||||
|
||||
export async function isSerieAvailable(serie: Serie, lang: SupportedLanguages) {
|
||||
if (!serie.name[lang]) {
|
||||
return false
|
||||
}
|
||||
const sets = (await getSets(serie.name.en, lang))
|
||||
return sets.length > 0
|
||||
}
|
||||
|
||||
export async function serieToSerieSimple(serie: Serie, lang: SupportedLanguages): Promise<SerieResume> {
|
||||
return {
|
||||
id: serie.id,
|
||||
@ -49,10 +48,8 @@ export async function serieToSerieSimple(serie: Serie, lang: SupportedLanguages)
|
||||
export async function serieToSerieSingle(serie: Serie, lang: SupportedLanguages): Promise<SerieSingle> {
|
||||
const setsTmp = await getSets(serie.name.en, lang)
|
||||
const sets = await Promise.all(setsTmp
|
||||
.sort((a, b) => {
|
||||
return a.releaseDate > b.releaseDate ? 1 : -1
|
||||
})
|
||||
.map(el => setToSetSimple(el, lang)))
|
||||
.sort((a, b) => a.releaseDate > b.releaseDate ? 1 : -1)
|
||||
.map((el) => setToSetSimple(el, lang)))
|
||||
return {
|
||||
id: serie.id,
|
||||
name: serie.name[lang] as string,
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Set, SupportedLanguages } from "db/interfaces"
|
||||
import { fetchRemoteFile, setIsLegal, smartGlob } from "./util"
|
||||
import { Set, SupportedLanguages } from 'db/interfaces'
|
||||
import { fetchRemoteFile, setIsLegal, smartGlob } from './util'
|
||||
import { cardToCardSimple, getCards } from './cardUtil'
|
||||
import { SetResume, Set as SetSingle } from '@tcgdex/sdk/interfaces'
|
||||
|
||||
@ -9,52 +9,46 @@ interface t {
|
||||
|
||||
const setCache: t = {}
|
||||
|
||||
// Dont use cache as it wont necessary have them all
|
||||
export async function getSets(serie = '*', lang: SupportedLanguages): Promise<Array<Set>> {
|
||||
// list sets names
|
||||
const rawSets = (await smartGlob(`./db/data/${serie}/*.js`)).map((set) => set.substring(set.lastIndexOf('/')+1, set.lastIndexOf('.')))
|
||||
// Fetch sets
|
||||
const sets = (await Promise.all(rawSets.map((set) => getSet(set, serie, lang))))
|
||||
// Filter sets
|
||||
.filter((set) => isSetAvailable(set, lang))
|
||||
// Sort sets by release date
|
||||
.sort((a, b) => {
|
||||
return a.releaseDate > b.releaseDate ? 1 : -1
|
||||
})
|
||||
return sets
|
||||
export function isSetAvailable(set: Set, lang: SupportedLanguages): boolean {
|
||||
return lang in set.name
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the set
|
||||
* @param name the name of the set (don't include.js/.ts)
|
||||
*/
|
||||
export async function getSet(name: string, serie = '*', lang: SupportedLanguages): Promise<Set> {
|
||||
export async function getSet(name: string, serie = '*'): Promise<Set> {
|
||||
if (!setCache[name]) {
|
||||
try {
|
||||
const [path] = await smartGlob(`./db/data/${serie}/${name}.js`)
|
||||
setCache[name] = (await import(path.replace('./', '../'))).default
|
||||
} catch (e) {
|
||||
const set = (await getSets(undefined, lang)).find((s) => s.id === name)
|
||||
if (set) {
|
||||
return set
|
||||
}
|
||||
console.error(e)
|
||||
console.error(`Error trying to import importing (${`db/data/*/${name}.js`})`)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
console.error(`Error trying to import importing (${`db/data/${serie}/${name}.js`})`)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
return setCache[name]
|
||||
}
|
||||
|
||||
export function isSetAvailable(set: Set, lang: SupportedLanguages): boolean {
|
||||
return lang in set.name && lang in set.serie.name
|
||||
// Dont use cache as it wont necessary have them all
|
||||
export async function getSets(serie = '*', lang: SupportedLanguages): Promise<Array<Set>> {
|
||||
// list sets names
|
||||
const rawSets = (await smartGlob(`./db/data/${serie}/*.js`)).map((set) => set.substring(set.lastIndexOf('/') + 1, set.lastIndexOf('.')))
|
||||
// Fetch sets
|
||||
const sets = (await Promise.all(rawSets.map((set) => getSet(set, serie))))
|
||||
// Filter sets
|
||||
.filter((set) => isSetAvailable(set, lang))
|
||||
// Sort sets by release date
|
||||
.sort((a, b) => a.releaseDate > b.releaseDate ? 1 : -1)
|
||||
return sets
|
||||
}
|
||||
|
||||
export async function getSetPictures(set: Set, lang: SupportedLanguages): Promise<[string | undefined, string | undefined]> {
|
||||
try {
|
||||
const file = await fetchRemoteFile(`https://assets.tcgdex.net/datas.json`)
|
||||
const logoExists = !!file[lang]?.[set.serie.id]?.[set.id]?.logo ? `https://assets.tcgdex.net/${lang}/${set.serie.id}/${set.id}/logo` : undefined
|
||||
const symbolExists = !!file.univ?.[set.serie.id]?.[set.id]?.symbol ? `https://assets.tcgdex.net/univ/${set.serie.id}/${set.id}/symbol` : undefined
|
||||
const file = await fetchRemoteFile('https://assets.tcgdex.net/datas.json')
|
||||
const logoExists = file[lang]?.[set.serie.id]?.[set.id]?.logo ? `https://assets.tcgdex.net/${lang}/${set.serie.id}/${set.id}/logo` : undefined
|
||||
const symbolExists = file.univ?.[set.serie.id]?.[set.id]?.symbol ? `https://assets.tcgdex.net/univ/${set.serie.id}/${set.id}/symbol` : undefined
|
||||
return [
|
||||
logoExists,
|
||||
symbolExists
|
||||
@ -68,14 +62,14 @@ export async function setToSetSimple(set: Set, lang: SupportedLanguages): Promis
|
||||
const cards = await getCards(lang, set)
|
||||
const pics = await getSetPictures(set, lang)
|
||||
return {
|
||||
cardCount: {
|
||||
official: set.cardCount.official,
|
||||
total: Math.max(set.cardCount.official, cards.length)
|
||||
},
|
||||
id: set.id,
|
||||
logo: pics[0],
|
||||
symbol: pics[1],
|
||||
name: set.name[lang] as string,
|
||||
cardCount: {
|
||||
total: Math.max(set.cardCount.official, cards.length),
|
||||
official: set.cardCount.official
|
||||
},
|
||||
symbol: pics[1]
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,28 +77,28 @@ export async function setToSetSingle(set: Set, lang: SupportedLanguages): Promis
|
||||
const cards = await getCards(lang, set)
|
||||
const pics = await getSetPictures(set, lang)
|
||||
return {
|
||||
name: set.name[lang] as string,
|
||||
cardCount: {
|
||||
firstEd: cards.reduce((count, card) => count + (card[1].variants?.firstEdition ?? set.variants?.firstEdition ? 1 : 0), 0),
|
||||
holo: cards.reduce((count, card) => count + (card[1].variants?.holo ?? set.variants?.holo ? 1 : 0), 0),
|
||||
normal: cards.reduce((count, card) => count + (card[1].variants?.normal ?? set.variants?.normal ? 1 : 0), 0),
|
||||
official: set.cardCount.official,
|
||||
reverse: cards.reduce((count, card) => count + (card[1].variants?.reverse ?? set.variants?.reverse ? 1 : 0), 0),
|
||||
total: Math.max(set.cardCount.official, cards.length)
|
||||
},
|
||||
cards: await Promise.all(cards.map(([id, card]) => cardToCardSimple(id, card, lang))),
|
||||
id: set.id,
|
||||
legal: {
|
||||
expanded: setIsLegal('expanded', set),
|
||||
standard: setIsLegal('standard', set)
|
||||
},
|
||||
logo: pics[0],
|
||||
name: set.name[lang] as string,
|
||||
releaseDate: set.releaseDate,
|
||||
serie: {
|
||||
id: set.serie.id,
|
||||
name: set.serie.name[lang] as string
|
||||
},
|
||||
tcgOnline: set.tcgOnline,
|
||||
cardCount: {
|
||||
total: Math.max(set.cardCount.official, cards.length),
|
||||
official: set.cardCount.official,
|
||||
normal: cards.reduce((count, card) => count + (card[1].variants?.normal ?? set.variants?.normal ? 1 : 0), 0),
|
||||
reverse: cards.reduce((count, card) => count + (card[1].variants?.reverse ?? set.variants?.reverse ? 1 : 0), 0),
|
||||
holo: cards.reduce((count, card) => count + (card[1].variants?.holo ?? set.variants?.holo ? 1 : 0), 0),
|
||||
firstEd: cards.reduce((count, card) => count + (card[1].variants?.firstEdition ?? set.variants?.firstEdition ? 1 : 0), 0),
|
||||
},
|
||||
releaseDate: set.releaseDate,
|
||||
legal: {
|
||||
standard: setIsLegal('standard', set),
|
||||
expanded: setIsLegal('expanded', set)
|
||||
},
|
||||
logo: pics[0],
|
||||
symbol: pics[1],
|
||||
cards: await Promise.all(cards.map(([id, card]) => cardToCardSimple(id, card, lang)))
|
||||
tcgOnline: set.tcgOnline
|
||||
}
|
||||
}
|
||||
|
@ -4,72 +4,73 @@ type translatable = 'types' | 'rarity' | 'stage' | 'category' | 'suffix' | 'abil
|
||||
|
||||
const translations: Record<string, Record<translatable, Record<string, string>>> = {
|
||||
fr: {
|
||||
types: {
|
||||
'Colorless': 'Incolore',
|
||||
'Darkness': 'Obscurité',
|
||||
'Dragon': 'Dragon',
|
||||
'Fairy': 'Fée',
|
||||
'Fighting': 'Combat',
|
||||
'Fire': 'Feu',
|
||||
'Grass': 'Plante',
|
||||
'Lightning': 'Électrique',
|
||||
'Metal': 'Métal',
|
||||
'Psychic': 'Psy',
|
||||
'Water': 'Eau'
|
||||
},
|
||||
rarity: {
|
||||
'None': 'Rien',
|
||||
'Common': 'Commune',
|
||||
'Uncommon': 'Non Commune',
|
||||
'Rare': 'Rare',
|
||||
'Ultra Rare': 'Ultra Rare',
|
||||
'Secret Rare': 'Magnifique rare'
|
||||
},
|
||||
stage: {
|
||||
"Basic": 'Base',
|
||||
"BREAK": 'TURBO',
|
||||
"LEVEL-UP": 'Niveau Sup',
|
||||
"MEGA": 'MÉGA',
|
||||
"RESTORED": 'RECRÉE',
|
||||
"Stage1": 'Niveau1',
|
||||
"Stage2": 'Biveau2',
|
||||
"VMAX": 'VMAX'
|
||||
},
|
||||
category: {
|
||||
Pokemon: 'Pokémon',
|
||||
Trainer: 'Dresseur',
|
||||
Energy: 'Énergie'
|
||||
},
|
||||
suffix: {
|
||||
'EX': 'EX',
|
||||
'GX': 'GX',
|
||||
'V': 'V',
|
||||
'Legend': 'LÉGENDE',
|
||||
'Prime': 'Prime',
|
||||
'SP': 'SP',
|
||||
'TAG TEAM-GX': 'TAG TEAM-GX',
|
||||
},
|
||||
abilityType: {
|
||||
'Pokemon Power': 'Pouvoir Pokémon',
|
||||
'Ability': 'Talent',
|
||||
'Ancient Trait': 'Trait Antique',
|
||||
'Poke-BODY': 'Poké-BODY',
|
||||
'Poke-POWER': 'Poké-POWER',
|
||||
'Ability': 'Talent',
|
||||
'Ancient Trait': 'Trait Antique'
|
||||
'Pokemon Power': 'Pouvoir Pokémon'
|
||||
},
|
||||
trainerType: {
|
||||
'Supporter': 'Supporter',
|
||||
'Item': 'Objet',
|
||||
'Stadium': 'Stade',
|
||||
'Tool': 'Outil',
|
||||
'Ace Spec': 'High-Tech',
|
||||
'Technical Machine': 'Machine Technique',
|
||||
'Goldenred Game Corner': 'Salle de jeu de Doublonville',
|
||||
'Rocket\'s Secret Machine': 'Machine secrète des Rocket'
|
||||
category: {
|
||||
Energy: 'Énergie',
|
||||
Pokemon: 'Pokémon',
|
||||
Trainer: 'Dresseur'
|
||||
},
|
||||
energyType: {
|
||||
Normal: 'Normal',
|
||||
Special: 'Spécial'
|
||||
},
|
||||
rarity: {
|
||||
'Common': 'Commune',
|
||||
'None': 'Rien',
|
||||
'Rare': 'Rare',
|
||||
'Secret Rare': 'Magnifique rare',
|
||||
'Ultra Rare': 'Ultra Rare',
|
||||
'Uncommon': 'Non Commune'
|
||||
},
|
||||
stage: {
|
||||
'BREAK': 'TURBO',
|
||||
'Basic': 'Base',
|
||||
'LEVEL-UP': 'Niveau Sup',
|
||||
'MEGA': 'MÉGA',
|
||||
'RESTORED': 'RECRÉE',
|
||||
'Stage1': 'Niveau1',
|
||||
'Stage2': 'Niveau2',
|
||||
'VMAX': 'VMAX'
|
||||
},
|
||||
suffix: {
|
||||
'EX': 'EX',
|
||||
'GX': 'GX',
|
||||
'Legend': 'LÉGENDE',
|
||||
'Prime': 'Prime',
|
||||
'SP': 'SP',
|
||||
'TAG TEAM-GX': 'TAG TEAM-GX',
|
||||
'V': 'V'
|
||||
},
|
||||
trainerType: {
|
||||
'Ace Spec': 'High-Tech',
|
||||
'Goldenred Game Corner': 'Salle de jeu de Doublonville',
|
||||
'Item': 'Objet',
|
||||
'Rocket\'s Secret Machine': 'Machine secrète des Rocket',
|
||||
'Stadium': 'Stade',
|
||||
'Supporter': 'Supporter',
|
||||
'Technical Machine': 'Machine Technique',
|
||||
'Tool': 'Outil'
|
||||
},
|
||||
types: {
|
||||
Colorless: 'Incolore',
|
||||
Darkness: 'Obscurité',
|
||||
Dragon: 'Dragon',
|
||||
Fairy: 'Fée',
|
||||
Fighting: 'Combat',
|
||||
Fire: 'Feu',
|
||||
Grass: 'Plante',
|
||||
Lightning: 'Électrique',
|
||||
Metal: 'Métal',
|
||||
Psychic: 'Psy',
|
||||
Water: 'Eau'
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,7 +83,7 @@ export default function translate(item: translatable, key: string | undefined, l
|
||||
}
|
||||
const res = translations[lang]?.[item]?.[key]
|
||||
if (!res) {
|
||||
throw new Error(`Could not find translation for ${lang}${item}.${key}`);
|
||||
throw new Error(`Could not find translation for ${lang}${item}.${key}`)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
@ -4,7 +4,11 @@ import fetch from 'node-fetch'
|
||||
import * as legals from '../db/legals'
|
||||
|
||||
export function urlize(str: string): string {
|
||||
return str.replace('?', '%3F').normalize('NFC').replace(/["'\u0300-\u036f]/g, "")
|
||||
return str
|
||||
.replace('?', '%3F')
|
||||
.normalize('NFC')
|
||||
// eslint-disable-next-line no-misleading-character-class
|
||||
.replace(/["'\u0300-\u036f]/gu, '')
|
||||
}
|
||||
|
||||
interface fileCacheInterface {
|
||||
@ -25,19 +29,21 @@ export async function fetchRemoteFile<T = any>(url: string): Promise<T> {
|
||||
|
||||
const globCache: Record<string, Array<string>> = {}
|
||||
|
||||
export async function smartGlob(query: string) {
|
||||
export async function smartGlob(query: string): Promise<Array<string>> {
|
||||
if (!globCache[query]) {
|
||||
globCache[query] = await new Promise((res) => glob(query, (err, matches) => res(matches)))
|
||||
globCache[query] = await new Promise((res) => {
|
||||
glob(query, (err, matches) => res(matches))
|
||||
})
|
||||
}
|
||||
return globCache[query]
|
||||
}
|
||||
|
||||
export function cardIsLegal(type: 'standard' | 'expanded', card: Card, localId: string) {
|
||||
export function cardIsLegal(type: 'standard' | 'expanded', card: Card, localId: string): boolean {
|
||||
const legal = legals[type]
|
||||
if (
|
||||
legal.includes.series.includes(card.set.serie.id) ||
|
||||
legal.includes.sets.includes(card.set.id) ||
|
||||
(card.regulationMark && legal.includes.regulationMark.includes(card.regulationMark))
|
||||
card.regulationMark && legal.includes.regulationMark.includes(card.regulationMark)
|
||||
) {
|
||||
return !(
|
||||
legal.excludes.sets.includes(card.set.id) ||
|
||||
@ -47,7 +53,7 @@ export function cardIsLegal(type: 'standard' | 'expanded', card: Card, localId:
|
||||
return false
|
||||
}
|
||||
|
||||
export function setIsLegal(type: 'standard' | 'expanded', set: Set) {
|
||||
export function setIsLegal(type: 'standard' | 'expanded', set: Set): boolean {
|
||||
const legal = legals[type]
|
||||
if (
|
||||
legal.includes.series.includes(set.serie.id) ||
|
||||
|
Reference in New Issue
Block a user