minecraft-crafting-info
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "minecraft-crafting-info", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Scrapes https://www.minecraftcrafting.info for crafting recipes.", | ||
@@ -5,0 +5,0 @@ "module": "src/index.ts", |
const REGEX = | ||
/<tr>\s*<td.*?>\s*(.+?)\s*<\/td>\s*<td.*?>\s*(.+?)\s*<\/td>\s*<td.*?>\s*<img.*?src="(.+?)".+?<\/td>\s*<td.*?>\s*(.+?)\s*<\/td>/gim; | ||
export const baseUrl = "https://www.minecraftcrafting.info"; | ||
export interface Recipe { | ||
@@ -9,9 +11,7 @@ itemName: string; | ||
materials: string; | ||
recipeImage: string; | ||
recipeImage: URL; | ||
} | ||
export async function fetchRecipes() { | ||
const html = await fetch("https://www.minecraftcrafting.info").then((r) => | ||
r.text() | ||
); | ||
const html = await fetch(baseUrl).then((r) => r.text()); | ||
@@ -23,3 +23,8 @@ const recipeMatches = html.matchAll(REGEX); | ||
const [, itemName, materials, recipeImage, itemDescription] = match; | ||
recipes.push({ itemName, itemDescription, recipeImage, materials }); | ||
recipes.push({ | ||
itemName, | ||
itemDescription, | ||
recipeImage: new URL(recipeImage, baseUrl), | ||
materials, | ||
}); | ||
} | ||
@@ -31,3 +36,3 @@ | ||
if (process.isBun && import.meta.main) { | ||
console.table(await fetchRecipes()); | ||
fetchRecipes().then(console.table); | ||
} |
1321
27