card-search-on-motorcycles
v0.0.0
Published
Fast generic card-name search, originally built for Yu-Gi-Oh.
Readme
Card Search On Motorcycles
Fast generic card-name search, originally built for Yu-Gi-Oh.
What it does
- Builds a fuzzy search index for card names.
- Runs browser-safe searches against a prebuilt index.
- Offers backend helpers for fetching, building, saving, and loading indexes.
- Preserves extra fields on your own card types through indexing and search results.
Install
npm i card-search-on-motorcyclesor
deno add jsr:card-search-on-motorcyclesBrowser-safe search
Use the root export when you already have card records or a serialized index.
import { buildCardIndex, findMatches, prepareSearchableCard } from "card-search-on-motorcycles"
const cards = [
prepareSearchableCard({
id: 1,
name: "Dark Magician",
archetype: "Dark Magician",
}),
]
const index = buildCardIndex(cards)
const { results } = findMatches("dark magician", index)
console.log(results[0].archetype)Backend caching
Caching is opt-in. If you do not pass cache paths, the library will not read or write cache files.
import { loadCardIndex } from "card-search-on-motorcycles/backend"
import { fetchCardData } from "card-search-on-motorcycles/yugioh"
const index = await loadCardIndex({
fetchCards: fetchCardData,
cardDataCacheFile: "./cache/cards.json",
indexCacheFile: "./cache/index.json",
indexGzipCacheFile: "./cache/index.json.gz",
})Entry points
card-search-on-motorcyclesexports browser-safe indexing, serialization, and search APIs.card-search-on-motorcycles/backendexports Deno file-cache helpers.card-search-on-motorcycles/yugiohexports YGOPRODeck fetching and mapping helpers.card-search-on-motorcycles/cliexports the interactive CLI script.
Development
Install Deno.
Run tests
deno test --parallel --allow-read --allow-write --allow-netThe real Yu-Gi-Oh search tests use the explicit test cache under /tmp/ytdb-cache. If that cache is missing, tests fetch data
from YGOPRODeck.
CLI Tool
Use this for playing around with the search.
./scripts/cli.shPublish
deno publishdeno run publish-npm