// Escapes any quotation marks in the given string with backslashes. const backslashEscapeQuotes = (str) => str .replace(/\\/g, '\\\\') // replace all \ with \\ .replace(/"/g, '\\"'); // replace all " with \" /** * Gets the internal ID of the named item from XIVAPI. * @param {string} name * @returns {Promise} */ export async function findItemGTID (name) { const query = `Name~"${backslashEscapeQuotes(name)}"`; const apiURL = `https://v2.xivapi.com/api/search?${new URLSearchParams({ sheets: 'Item', query, fields: 'Name', })}`; const response = await fetch(apiURL); const data = await response.json(); if (!response.ok) { throw new Error(`XIVAPI request failed: ${data.code} ${data.message}`); } const item = data.results.find(item => item.fields.Name.toLowerCase() === name.toLowerCase()); return item?.row_id ?? null; }