diff options
Diffstat (limited to 'docusaurus/static/ajax/libs/wolfree/23.7.8/js/AJAX.js')
-rw-r--r-- | docusaurus/static/ajax/libs/wolfree/23.7.8/js/AJAX.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/docusaurus/static/ajax/libs/wolfree/23.7.8/js/AJAX.js b/docusaurus/static/ajax/libs/wolfree/23.7.8/js/AJAX.js new file mode 100644 index 0000000..465787d --- /dev/null +++ b/docusaurus/static/ajax/libs/wolfree/23.7.8/js/AJAX.js @@ -0,0 +1,56 @@ +/** + * @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 }; + } + }; +} |