@shaivpidadi/trends-js 0.0.0-beta.6 → 0.0.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +183 -38
  2. package/dist/cjs/constants.d.ts +3 -0
  3. package/{lib → dist/cjs}/constants.js +19 -4
  4. package/{lib → dist/cjs}/helpers/googleTrendsAPI.d.ts +4 -1
  5. package/dist/cjs/helpers/googleTrendsAPI.js +339 -0
  6. package/{lib → dist/cjs}/helpers/request.d.ts +1 -1
  7. package/{lib → dist/cjs}/helpers/request.js +14 -18
  8. package/dist/cjs/index.d.ts +19 -0
  9. package/dist/cjs/index.js +24 -0
  10. package/dist/cjs/types/enums.d.ts +14 -0
  11. package/dist/cjs/types/enums.js +19 -0
  12. package/dist/esm/constants.d.ts +3 -0
  13. package/dist/esm/constants.js +50 -0
  14. package/dist/esm/errors/GoogleTrendsError.d.ts +23 -0
  15. package/dist/esm/errors/GoogleTrendsError.js +37 -0
  16. package/dist/esm/helpers/format.d.ts +2 -0
  17. package/dist/esm/helpers/format.js +76 -0
  18. package/dist/esm/helpers/googleTrendsAPI.d.ts +29 -0
  19. package/dist/esm/helpers/googleTrendsAPI.js +335 -0
  20. package/dist/esm/helpers/request.d.ts +9 -0
  21. package/dist/esm/helpers/request.js +75 -0
  22. package/dist/esm/index.d.ts +19 -0
  23. package/dist/esm/index.js +21 -0
  24. package/dist/esm/types/enums.d.ts +14 -0
  25. package/dist/esm/types/enums.js +16 -0
  26. package/package.json +29 -35
  27. package/lib/constants.d.ts +0 -2
  28. package/lib/helpers/googleTrendsAPI.js +0 -211
  29. package/lib/index.d.ts +0 -2
  30. package/lib/index.js +0 -7
  31. /package/{lib → dist/cjs}/errors/GoogleTrendsError.d.ts +0 -0
  32. /package/{lib → dist/cjs}/errors/GoogleTrendsError.js +0 -0
  33. /package/{lib → dist/cjs}/helpers/format.d.ts +0 -0
  34. /package/{lib → dist/cjs}/helpers/format.js +0 -0
package/README.md CHANGED
@@ -17,6 +17,9 @@ npm install @shaivpidadi/trends-js
17
17
  - Get autocomplete suggestions
18
18
  - Explore trends data
19
19
  - Get interest by region data
20
+ - Get related topics for any keyword
21
+ - Get related queries for any keyword
22
+ - Get combined related data (topics + queries)
20
23
  - TypeScript support
21
24
  - Promise-based API
22
25
 
@@ -33,9 +36,9 @@ import GoogleTrendsApi from '@shaivpidadi/trends-js';
33
36
  Get daily trending topics for a specific region:
34
37
 
35
38
  ```typescript
36
- const result = await GoogleTrendsApi.dailyTrends({
37
- geo: 'US', // Default: 'US'
38
- lang: 'en' // Default: 'en'
39
+ const result = await GoogleTrendsApi.dailyTrends({
40
+ geo: 'US', // Default: 'US'
41
+ lang: 'en', // Default: 'en'
39
42
  });
40
43
 
41
44
  // Result structure:
@@ -50,9 +53,9 @@ const result = await GoogleTrendsApi.dailyTrends({
50
53
  Get real-time trending topics:
51
54
 
52
55
  ```typescript
53
- const result = await GoogleTrendsApi.realTimeTrends({
54
- geo: 'US', // Default: 'US'
55
- trendingHours: 4 // Default: 4
56
+ const result = await GoogleTrendsApi.realTimeTrends({
57
+ geo: 'US', // Default: 'US'
58
+ trendingHours: 4, // Default: 4
56
59
  });
57
60
 
58
61
  // Result structure:
@@ -68,8 +71,8 @@ Get search suggestions for a keyword:
68
71
 
69
72
  ```typescript
70
73
  const suggestions = await GoogleTrendsApi.autocomplete(
71
- 'bitcoin', // Keyword to get suggestions for
72
- 'en-US' // Language (default: 'en-US')
74
+ 'bitcoin', // Keyword to get suggestions for
75
+ 'en-US', // Language (default: 'en-US')
73
76
  );
74
77
 
75
78
  // Returns: string[]
@@ -80,13 +83,13 @@ const suggestions = await GoogleTrendsApi.autocomplete(
80
83
  Get widget data for a keyword:
81
84
 
82
85
  ```typescript
83
- const result = await GoogleTrendsApi.explore({
86
+ const result = await GoogleTrendsApi.explore({
84
87
  keyword: 'bitcoin',
85
- geo: 'US', // Default: 'US'
86
- time: 'today 12-m', // Default: 'today 12-m'
87
- category: 0, // Default: 0
88
- property: '', // Default: ''
89
- hl: 'en-US' // Default: 'en-US'
88
+ geo: 'US', // Default: 'US'
89
+ time: 'today 12-m', // Default: 'today 12-m'
90
+ category: 0, // Default: 0
91
+ property: '', // Default: ''
92
+ hl: 'en-US', // Default: 'en-US'
90
93
  });
91
94
 
92
95
  // Result structure:
@@ -104,15 +107,15 @@ const result = await GoogleTrendsApi.explore({
104
107
  Get interest data by region:
105
108
 
106
109
  ```typescript
107
- const result = await GoogleTrendsApi.interestByRegion({
108
- keyword: 'Stock Market', // Required - string or string[]
110
+ const result = await GoogleTrendsApi.interestByRegion({
111
+ keyword: 'Stock Market', // Required - string or string[]
109
112
  startTime: new Date('2024-01-01'), // Optional - defaults to 2004-01-01
110
- endTime: new Date(), // Optional - defaults to current date
111
- geo: 'US', // Optional - string or string[] - defaults to 'US'
112
- resolution: 'REGION', // Optional - 'COUNTRY' | 'REGION' | 'CITY' | 'DMA'
113
- hl: 'en-US', // Optional - defaults to 'en-US'
114
- timezone: -240, // Optional - defaults to local timezone
115
- category: 0 // Optional - defaults to 0
113
+ endTime: new Date(), // Optional - defaults to current date
114
+ geo: 'US', // Optional - string or string[] - defaults to 'US'
115
+ resolution: 'REGION', // Optional - 'COUNTRY' | 'REGION' | 'CITY' | 'DMA'
116
+ hl: 'en-US', // Optional - defaults to 'en-US'
117
+ timezone: -240, // Optional - defaults to local timezone
118
+ category: 0, // Optional - defaults to 0
116
119
  });
117
120
 
118
121
  // Result structure:
@@ -137,22 +140,113 @@ const result = await GoogleTrendsApi.interestByRegion({
137
140
  Example with multiple keywords and regions:
138
141
 
139
142
  ```typescript
140
- const result = await GoogleTrendsApi.interestByRegion({
143
+ const result = await GoogleTrendsApi.interestByRegion({
141
144
  keyword: ['wine', 'peanuts'],
142
145
  geo: ['US-CA', 'US-VA'],
143
146
  startTime: new Date('2024-01-01'),
144
147
  endTime: new Date(),
145
- resolution: 'CITY'
148
+ resolution: 'CITY',
146
149
  });
147
150
  ```
148
151
 
152
+ ### Related Topics
153
+
154
+ Get related topics for any keyword:
155
+
156
+ ```typescript
157
+ const result = await GoogleTrendsApi.relatedTopics({
158
+ keyword: 'artificial intelligence', // Required
159
+ geo: 'US', // Optional - defaults to 'US'
160
+ time: 'now 1-d', // Optional - defaults to 'now 1-d'
161
+ category: 0, // Optional - defaults to 0
162
+ property: '', // Optional - defaults to ''
163
+ hl: 'en-US', // Optional - defaults to 'en-US'
164
+ });
165
+
166
+ // Result structure:
167
+ // {
168
+ // data: {
169
+ // default: {
170
+ // rankedList: Array<{
171
+ // rankedKeyword: Array<{
172
+ // topic: {
173
+ // mid: string,
174
+ // title: string,
175
+ // type: string
176
+ // },
177
+ // value: number,
178
+ // formattedValue: string,
179
+ // hasData: boolean,
180
+ // link: string
181
+ // }>
182
+ // }>
183
+ // }
184
+ // }
185
+ // }
186
+ ```
187
+
188
+ ### Related Queries
189
+
190
+ Get related queries for any keyword:
191
+
192
+ ```typescript
193
+ const result = await GoogleTrendsApi.relatedQueries({
194
+ keyword: 'machine learning', // Required
195
+ geo: 'US', // Optional - defaults to 'US'
196
+ time: 'now 1-d', // Optional - defaults to 'now 1-d'
197
+ category: 0, // Optional - defaults to 0
198
+ property: '', // Optional - defaults to ''
199
+ hl: 'en-US', // Optional - defaults to 'en-US'
200
+ });
201
+
202
+ // Result structure:
203
+ // {
204
+ // data: {
205
+ // default: {
206
+ // rankedList: Array<{
207
+ // rankedKeyword: Array<{
208
+ // query: string,
209
+ // value: number,
210
+ // formattedValue: string,
211
+ // hasData: boolean,
212
+ // link: string
213
+ // }>
214
+ // }>
215
+ // }
216
+ // }
217
+ // }
218
+ ```
219
+
220
+ ### Combined Related Data
221
+
222
+ Get both related topics and queries in a single call:
223
+
224
+ ```typescript
225
+ const result = await GoogleTrendsApi.relatedData({
226
+ keyword: 'blockchain', // Required
227
+ geo: 'US', // Optional - defaults to 'US'
228
+ time: 'now 1-d', // Optional - defaults to 'now 1-d'
229
+ category: 0, // Optional - defaults to 0
230
+ property: '', // Optional - defaults to ''
231
+ hl: 'en-US', // Optional - defaults to 'en-US'
232
+ });
233
+
234
+ // Result structure:
235
+ // {
236
+ // data: {
237
+ // topics: Array<RelatedTopic>,
238
+ // queries: Array<RelatedQuery>
239
+ // }
240
+ // }
241
+ ```
242
+
149
243
  ## API Reference
150
244
 
151
245
  ### DailyTrendsOptions
152
246
 
153
247
  ```typescript
154
248
  interface DailyTrendsOptions {
155
- geo?: string; // Default: 'US'
249
+ geo?: string; // Default: 'US'
156
250
  lang?: string; // Default: 'en'
157
251
  }
158
252
  ```
@@ -171,11 +265,11 @@ interface RealTimeTrendsOptions {
171
265
  ```typescript
172
266
  interface ExploreOptions {
173
267
  keyword: string;
174
- geo?: string; // Default: 'US'
175
- time?: string; // Default: 'today 12-m'
176
- category?: number; // Default: 0
177
- property?: string; // Default: ''
178
- hl?: string; // Default: 'en-US'
268
+ geo?: string; // Default: 'US'
269
+ time?: string; // Default: 'today 12-m'
270
+ category?: number; // Default: 0
271
+ property?: string; // Default: ''
272
+ hl?: string; // Default: 'en-US'
179
273
  }
180
274
  ```
181
275
 
@@ -183,14 +277,63 @@ interface ExploreOptions {
183
277
 
184
278
  ```typescript
185
279
  interface InterestByRegionOptions {
186
- keyword: string | string[]; // Required - search term(s)
187
- startTime?: Date; // Optional - start date
188
- endTime?: Date; // Optional - end date
189
- geo?: string | string[]; // Optional - geocode(s)
280
+ keyword: string | string[]; // Required - search term(s)
281
+ startTime?: Date; // Optional - start date
282
+ endTime?: Date; // Optional - end date
283
+ geo?: string | string[]; // Optional - geocode(s)
190
284
  resolution?: 'COUNTRY' | 'REGION' | 'CITY' | 'DMA'; // Optional
191
- hl?: string; // Optional - language code
192
- timezone?: number; // Optional - timezone offset
193
- category?: number; // Optional - category number
285
+ hl?: string; // Optional - language code
286
+ timezone?: number; // Optional - timezone offset
287
+ category?: number; // Optional - category number
288
+ }
289
+ ```
290
+
291
+ ### RelatedTopicsResponse
292
+
293
+ ```typescript
294
+ interface RelatedTopicsResponse {
295
+ default: {
296
+ rankedList: Array<{
297
+ rankedKeyword: Array<{
298
+ topic: {
299
+ mid: string;
300
+ title: string;
301
+ type: string;
302
+ };
303
+ value: number;
304
+ formattedValue: string;
305
+ hasData: boolean;
306
+ link: string;
307
+ }>;
308
+ }>;
309
+ };
310
+ }
311
+ ```
312
+
313
+ ### RelatedQueriesResponse
314
+
315
+ ```typescript
316
+ interface RelatedQueriesResponse {
317
+ default: {
318
+ rankedList: Array<{
319
+ rankedKeyword: Array<{
320
+ query: string;
321
+ value: number;
322
+ formattedValue: string;
323
+ hasData: boolean;
324
+ link: string;
325
+ }>;
326
+ }>;
327
+ };
328
+ }
329
+ ```
330
+
331
+ ### RelatedData
332
+
333
+ ```typescript
334
+ interface RelatedData {
335
+ topics: Array<RelatedTopic>;
336
+ queries: Array<RelatedQuery>;
194
337
  }
195
338
  ```
196
339
 
@@ -198,4 +341,6 @@ interface InterestByRegionOptions {
198
341
 
199
342
  ### Building
200
343
 
201
- ```
344
+ ```
345
+
346
+ ```
@@ -0,0 +1,3 @@
1
+ import { GoogleTrendsEndpoints } from './types/enums';
2
+ import { GoogleTrendsMapper } from './types';
3
+ export declare const GOOGLE_TRENDS_MAPPER: Record<GoogleTrendsEndpoints, GoogleTrendsMapper>;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GOOGLE_TRENDS_MAPPER = void 0;
4
+ const enums_1 = require("./types/enums");
4
5
  const GOOGLE_TRENDS_BASE_URL = 'trends.google.com';
5
6
  exports.GOOGLE_TRENDS_MAPPER = {
6
- ["dailyTrends" /* GoogleTrendsEndpoints.dailyTrends */]: {
7
+ [enums_1.GoogleTrendsEndpoints.dailyTrends]: {
7
8
  path: '/_/TrendsUi/data/batchexecute',
8
9
  method: 'POST',
9
10
  host: GOOGLE_TRENDS_BASE_URL,
@@ -12,7 +13,7 @@ exports.GOOGLE_TRENDS_MAPPER = {
12
13
  'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
13
14
  },
14
15
  },
15
- ["autocomplete" /* GoogleTrendsEndpoints.autocomplete */]: {
16
+ [enums_1.GoogleTrendsEndpoints.autocomplete]: {
16
17
  path: '/trends/api/autocomplete',
17
18
  method: 'GET',
18
19
  host: GOOGLE_TRENDS_BASE_URL,
@@ -21,18 +22,32 @@ exports.GOOGLE_TRENDS_MAPPER = {
21
22
  accept: 'application/json, text/plain, */*',
22
23
  },
23
24
  },
24
- ["explore" /* GoogleTrendsEndpoints.explore */]: {
25
+ [enums_1.GoogleTrendsEndpoints.explore]: {
25
26
  path: '/trends/api/explore',
26
27
  method: 'POST',
27
28
  host: GOOGLE_TRENDS_BASE_URL,
28
29
  url: `https://${GOOGLE_TRENDS_BASE_URL}/trends/api/explore`,
29
30
  headers: {},
30
31
  },
31
- ["interestByRegion" /* GoogleTrendsEndpoints.interestByRegion */]: {
32
+ [enums_1.GoogleTrendsEndpoints.interestByRegion]: {
32
33
  path: '/trends/api/widgetdata/comparedgeo',
33
34
  method: 'GET',
34
35
  host: GOOGLE_TRENDS_BASE_URL,
35
36
  url: `https://${GOOGLE_TRENDS_BASE_URL}/trends/api/widgetdata/comparedgeo`,
36
37
  headers: {},
37
38
  },
39
+ [enums_1.GoogleTrendsEndpoints.relatedTopics]: {
40
+ path: '/trends/api/widgetdata/relatedtopics',
41
+ method: 'GET',
42
+ host: GOOGLE_TRENDS_BASE_URL,
43
+ url: `https://${GOOGLE_TRENDS_BASE_URL}/trends/api/widgetdata/relatedtopics`,
44
+ headers: {},
45
+ },
46
+ [enums_1.GoogleTrendsEndpoints.relatedQueries]: {
47
+ path: '/trends/api/widgetdata/relatedqueries',
48
+ method: 'GET',
49
+ host: GOOGLE_TRENDS_BASE_URL,
50
+ url: `https://${GOOGLE_TRENDS_BASE_URL}/trends/api/widgetdata/relatedqueries`,
51
+ headers: {},
52
+ },
38
53
  };
@@ -1,4 +1,4 @@
1
- import { DailyTrendingTopics, DailyTrendingTopicsOptions, RealTimeTrendsOptions, ExploreOptions, ExploreResponse, InterestByRegionOptions, InterestByRegionResponse, GoogleTrendsResponse } from '../types/index';
1
+ import { DailyTrendingTopics, DailyTrendingTopicsOptions, RealTimeTrendsOptions, ExploreOptions, ExploreResponse, InterestByRegionOptions, InterestByRegionResponse, GoogleTrendsResponse, RelatedTopicsResponse, RelatedQueriesResponse, RelatedData } from '../types/index';
2
2
  export declare class GoogleTrendsApi {
3
3
  /**
4
4
  * Get autocomplete suggestions for a keyword
@@ -21,6 +21,9 @@ export declare class GoogleTrendsApi {
21
21
  realTimeTrends({ geo, trendingHours }: RealTimeTrendsOptions): Promise<GoogleTrendsResponse<DailyTrendingTopics>>;
22
22
  explore({ keyword, geo, time, category, property, hl, }: ExploreOptions): Promise<ExploreResponse>;
23
23
  interestByRegion({ keyword, startTime, endTime, geo, resolution, hl, timezone, category }: InterestByRegionOptions): Promise<InterestByRegionResponse>;
24
+ relatedTopics({ keyword, geo, time, category, property, hl, }: ExploreOptions): Promise<GoogleTrendsResponse<RelatedTopicsResponse>>;
25
+ relatedQueries({ keyword, geo, time, category, property, hl, }: ExploreOptions): Promise<GoogleTrendsResponse<RelatedQueriesResponse>>;
26
+ relatedData({ keyword, geo, time, category, property, hl, }: ExploreOptions): Promise<GoogleTrendsResponse<RelatedData>>;
24
27
  }
25
28
  declare const _default: GoogleTrendsApi;
26
29
  export default _default;