google-trends-api-client
Version:
An fully typed and easy to use client for the google trends api.
28 lines • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAutocompleteSuggestions = void 0;
const defineCommonGoogleTrendsApiParametersValue_1 = require("../assertions/defineCommonGoogleTrendsApiParametersValue");
const getFromApiCall_1 = require("./getFromApiCall");
/**
* provides suggestions of search terms and topics which you can get trends data on
*
* for example:
* - https://trends.google.com/trends/api/autocomplete/mattress?hl=en-US&tz=240
*/
const getAutocompleteSuggestions = async ({ keyword, hl, tz }, agentOptions = {}) => {
const response = await (0, getFromApiCall_1.getFromApiCall)({
path: 'trends/api/autocomplete/:keyword',
agentOptions,
pathParams: {
keyword,
},
queryParams: {
...(0, defineCommonGoogleTrendsApiParametersValue_1.defineCommonGoogleTrendsApiParametersValue)({ hl, tz }),
},
});
const resultJson = response.replace(/^([^{]+)/g, ''); // for somereason, resopnse starts with `)]}',\n`, so delete everything before the first `{`
const result = JSON.parse(resultJson);
return result.default.topics;
};
exports.getAutocompleteSuggestions = getAutocompleteSuggestions;
//# sourceMappingURL=getAutocompleteSuggestions.js.map