UNPKG

@tanzanite/wolfram-alpha

Version:
146 lines 6.21 kB
/** * We support four 'output' formats: * 'string' and 'xml' are both strings, * 'json' is an Object (a result of JSON.parse), and * 'image' is a string of a "Data URI" */ declare type OutputFormat = "string" | "json" | "image" | "xml"; /** * @example {url: 'https://api.wolframalpha.com/v1/result?appid=DEMO&i=2%2B2', output: 'string'} */ export interface FetchParams { /** * full URL of api call */ url: string; /** * which OutputFormat do we want? */ output: OutputFormat; } /** * @example * ``` * { * data: '4', * output: 'string', * statusCode: 200, * contentType: 'text/plain;charset=utf-8' * } * ``` */ export interface FormatParams { /** * data returned by fetchResults */ data: string; /** * which OutputFormat do we want? */ output: OutputFormat; /** * HTTP status code of fetchResults */ statusCode: number; /** * HTTP content-type header from fetchResults */ contentType: string; } declare type DataURI = string; /** * Wolfram|Alpha API NPM Library */ export declare class WolframAlphaAPI { appid: string; /** * You may get your 'appid' at {@link https://developer.wolframalpha.com/portal/myapps/}. * Remember, this appID must be kept secret. * @param appid - the appid, must be non-empty string. * @throws TypeError * @example * const WolframAlphaAPI = require('wolfram-alpha-api'); * const waApi = WolframAlphaAPI('DEMO-APPID'); */ constructor(appid: string); /** * Takes 'input' (which is either a string, or an object of parameters), runs it through * the Wolfram|Alpha Simple API, and returns a Promise that * resolves a string of a "Data URI", or rejects if there's an error. * @param input - string or object of parameters * @see https://products.wolframalpha.com/simple-api/documentation/ * @example * // "data:image/gif;base64,R0lGODlhHAK5AvcAAAAAAAAEAAgICAgMCBAQEBAUEBsdGzE0MTk8OTk4OS0uLSAkI... * waApi.getSimple('2+2').then(console.log, console.error); * // "data:image/gif;base64,R0lGODlhHAJNBfcAAAAAAAAEAAgICAgMCBAQEBAUEBgYGBgcGCAgICAkICksKSkoK... * waApi.getSimple({i: 'nyc to la', units: 'metric'}).then(console.log, console.error); * // Error: Wolfram|Alpha did not understand your input * waApi.getSimple('F9TVlu5AmVzL').then(console.log, console.error); * // TypeError: method only receives string or object * waApi.getSimple().then(console.log, console.error); */ getSimple(input: string | Record<string, string | number | boolean | undefined>): Promise<DataURI>; /** * Takes 'input' (which is either a string, or an object of parameters), runs it through * the Wolfram|Alpha Short Answers API, and returns a Promise that * resolves a string of results, or rejects if there's an error. * @param input - string or object of parameters * @see https://products.wolframalpha.com/short-answers-api/documentation/ * @example * // "4" * waApi.getShort('2+2').then(console.log, console.error); * // "3966 kilometers" * waApi.getShort({i: 'nyc to la', units: 'metric'}).then(console.log, console.error); * // Error: Wolfram|Alpha did not understand your input * waApi.getShort('F9TVlu5AmVzL').then(console.log, console.error); * // TypeError: method only receives string or object * waApi.getShort().then(console.log, console.error); */ getShort(input: string | Record<string, string | number | boolean | undefined>): Promise<string>; /** * Takes 'input' (which is either a string, or an object of parameters), runs it through * the Wolfram|Alpha Spoken Results API, and returns a Promise that * resolves a string of results, or rejects if there's an error. * @param input - string or object of parameters * @see https://products.wolframalpha.com/spoken-results-api/documentation/ * @example * // "The answer is 4" * waApi.getSpoken('2+2').then(console.log, console.error); * // "The answer is about 3966 kilometers" * waApi.getSpoken({i: 'nyc to la', units: 'metric'}).then(console.log, console.error); * // Error: Wolfram Alpha did not understand your input * waApi.getSpoken('F9TVlu5AmVzL').then(console.log, console.error); * // TypeError: method only receives string or object * waApi.getSpoken().then(console.log, console.error); */ getSpoken(input: string | Record<string, string | number | boolean | undefined>): Promise<string>; /** * Takes 'input' (which is either a string, or an object of parameters), runs it through * the Wolfram|Alpha Full Results API, and returns a Promise that * either resolves an Object or a string of XML, or rejects if there's an error. * @param input - string or object of parameters * @see https://products.wolframalpha.com/api/documentation/ * @example * // {success: true, error: false, numpods: 6, datatypes: 'Math', timedout: '', timing: 1.08 ... * waApi.getFull('2+2').then(console.log, console.error); * // "<queryresult success='true' error='false' numpods='7' ... * waApi.getFull({input:'nyc to la', output:'xml'}).then(console.log, console.error); * // { success: false, error: false, numpods: 0, datatypes: '', timedout: '', ... * waApi.getFull('F9TVlu5AmVzL').then(console.log, console.error) * // TypeError: method only receives string or object * waApi.getFull().then(console.log, console.error); */ getFull(input: string | Record<string, string | number | boolean | undefined>): Promise<Record<string, string | number | boolean> | string>; } /** * You may get your 'appid' at {@link https://developer.wolframalpha.com/portal/myapps/}. * Remember, this appID must be kept secret. * @param appid - the appid, must be non-empty string. * @throws TypeError * @example * const WolframAlphaAPI = require('wolfram-alpha-api'); * const waApi = WolframAlphaAPI('DEMO-APPID'); */ export declare function initializeClass(appid: string): WolframAlphaAPI; export default initializeClass; //# sourceMappingURL=index.d.ts.map