/** * @license * SPDX-License-Identifier: AGPL-3.0-or-later * This file is part of Wolfree. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. */ // @ts-check import SearchParams from "./SearchParams.js"; export default class AJAX { ajax = async ({ input = String(), i2d = Boolean(), extraPodstates = Array(), } = {}) => { try { const data = new SearchParams().getSearchParams({ input, extraPodstates, i2d, }); const options = { url: "https://api.wolframalpha.com/v2/query", dataType: "jsonp", traditional: true, data, }; try { /** * https://www.npmjs.com/package/@types/jquery * @type {import('jQuery')} */ const response = await jQuery.ajax(options); return ( console.assert(response instanceof Object), console.assert(response.hasOwnProperty("queryresult")), { response } ); } catch (error) { return ( console.error( { error }, "We encountered an issue while attempting to retrieve a response from the Wolfram Alpha API using the jQuery library." ), { error } ); } } catch (error) { return console.error({ error }), { error }; } }; }