Skip to content

Commit 0b49cf7

Browse files
committed
Update jsdoc
1 parent fc4dd90 commit 0b49cf7

2 files changed

Lines changed: 22 additions & 28 deletions

File tree

README.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ Get a JSON response based on search parameters.
134134
135135
#### Parameters
136136
137-
- `engine`
138-
**[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
139-
engine name
140137
- `parameters`
141138
**[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
142139
search query parameters for the engine
@@ -146,21 +143,21 @@ Get a JSON response based on search parameters.
146143
147144
```javascript
148145
// single call (async/await)
149-
const json = await getJson("google", { api_key: API_KEY, q: "coffee" });
146+
const json = await getJson({ engine: "google", api_key: API_KEY, q: "coffee" });
150147

151148
// single call (callback)
152-
getJson("google", { api_key: API_KEY, q: "coffee" }, console.log);
149+
getJson({ engine: "google", api_key: API_KEY, q: "coffee" }, console.log);
153150
```
154151
155152
```javascript
156153
// pagination (async/await)
157-
const page1 = await getJson("google", { q: "coffee", start: 15 });
154+
const page1 = await getJson({ engine: "google", q: "coffee", start: 15 });
158155
const page2 = await page1.next?.();
159156
```
160157
161158
```javascript
162159
// pagination (callback)
163-
getJson("google", { q: "coffee", start: 15 }, (page1) => {
160+
getJson({ engine: "google", q: "coffee", start: 15 }, (page1) => {
164161
page1.next?.((page2) => {
165162
console.log(page2);
166163
});
@@ -170,7 +167,7 @@ getJson("google", { q: "coffee", start: 15 }, (page1) => {
170167
```javascript
171168
// pagination loop (async/await)
172169
const organicResults = [];
173-
let page = await getJson("google", { api_key: API_KEY, q: "coffee" });
170+
let page = await getJson({ engine: "google", api_key: API_KEY, q: "coffee" });
174171
while (page) {
175172
organicResults.push(...page.organic_results);
176173
if (organicResults.length >= 30) break;
@@ -181,7 +178,7 @@ while (page) {
181178
```javascript
182179
// pagination loop (callback)
183180
const organicResults = [];
184-
getJson("google", { api_key: API_KEY, q: "coffee" }, (page) => {
181+
getJson({ engine: "google", api_key: API_KEY, q: "coffee" }, (page) => {
185182
organicResults.push(...page.organic_results);
186183
if (organicResults.length < 30 && page.next) {
187184
page.next();
@@ -198,9 +195,6 @@ Get a HTML response based on search parameters.
198195
199196
#### Parameters
200197
201-
- `engine`
202-
**[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
203-
engine name
204198
- `parameters`
205199
**[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
206200
search query parameters for the engine
@@ -210,10 +204,10 @@ Get a HTML response based on search parameters.
210204
211205
```javascript
212206
// async/await
213-
const html = await getHtml("google", { api_key: API_KEY, q: "coffee" });
207+
const html = await getHtml({ engine: "google", api_key: API_KEY, q: "coffee" });
214208

215209
// callback
216-
getHtml("google", { api_key: API_KEY, q: "coffee" }, console.log);
210+
getHtml({ engine: "google", api_key: API_KEY, q: "coffee" }, console.log);
217211
```
218212
219213
### getJsonBySearchId
@@ -245,7 +239,8 @@ Get a JSON response given a search ID.
245239
#### Examples
246240
247241
```javascript
248-
const response = await getJson("google", {
242+
const response = await getJson({
243+
engine: "google",
249244
api_key: API_KEY,
250245
async: true,
251246
q: "coffee",
@@ -290,7 +285,8 @@ Get a HTML response given a search ID.
290285
#### Examples
291286
292287
```javascript
293-
const response = await getJson("google", {
288+
const response = await getJson({
289+
engine: "google",
294290
api_key: API_KEY,
295291
async: true,
296292
q: "coffee",

src/serpapi.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,23 @@ const SEARCH_ARCHIVE_PATH = `/searches`;
2727
* - Accepts an optional callback.
2828
* - Get the next page of results by calling the `.next()` method on the returned response object.
2929
*
30-
* @param {string} engine - engine name
3130
* @param {object} parameters - search query parameters for the engine
3231
* @param {fn=} callback - optional callback
3332
* @example
3433
* // single call (async/await)
35-
* const json = await getJson("google", { api_key: API_KEY, q: "coffee" });
34+
* const json = await getJson({ engine: "google", api_key: API_KEY, q: "coffee" });
3635
*
3736
* // single call (callback)
38-
* getJson("google", { api_key: API_KEY, q: "coffee" }, console.log);
37+
* getJson({ engine: "google", api_key: API_KEY, q: "coffee" }, console.log);
3938
*
4039
* @example
4140
* // pagination (async/await)
42-
* const page1 = await getJson("google", { q: "coffee", start: 15 });
41+
* const page1 = await getJson({ engine: "google", q: "coffee", start: 15 });
4342
* const page2 = await page1.next?.();
4443
*
4544
* @example
4645
* // pagination (callback)
47-
* getJson("google", { q: "coffee", start: 15 }, (page1) => {
46+
* getJson({ engine: "google", q: "coffee", start: 15 }, (page1) => {
4847
* page1.next?.((page2) => {
4948
* console.log(page2);
5049
* });
@@ -53,7 +52,7 @@ const SEARCH_ARCHIVE_PATH = `/searches`;
5352
* @example
5453
* // pagination loop (async/await)
5554
* const organicResults = [];
56-
* let page = await getJson("google", { api_key: API_KEY, q: "coffee" });
55+
* let page = await getJson({ engine: "google", api_key: API_KEY, q: "coffee" });
5756
* while (page) {
5857
* organicResults.push(...page.organic_results);
5958
* if (organicResults.length >= 30) break;
@@ -63,7 +62,7 @@ const SEARCH_ARCHIVE_PATH = `/searches`;
6362
* @example
6463
* // pagination loop (callback)
6564
* const organicResults = [];
66-
* getJson("google", { api_key: API_KEY, q: "coffee" }, (page) => {
65+
* getJson({ engine: "google", api_key: API_KEY, q: "coffee" }, (page) => {
6766
* organicResults.push(...page.organic_results);
6867
* if (organicResults.length < 30 && page.next) {
6968
* page.next();
@@ -114,15 +113,14 @@ export async function getJson<
114113
* - Accepts an optional callback.
115114
* - Responds with a JSON string if the search request hasn't completed.
116115
*
117-
* @param {string} engine - engine name
118116
* @param {object} parameters - search query parameters for the engine
119117
* @param {fn=} callback - optional callback
120118
* @example
121119
* // async/await
122-
* const html = await getHtml("google", { api_key: API_KEY, q: "coffee" });
120+
* const html = await getHtml({ engine: "google", api_key: API_KEY, q: "coffee" });
123121
*
124122
* // callback
125-
* getHtml("google", { api_key: API_KEY, q: "coffee" }, console.log);
123+
* getHtml({ engine: "google", api_key: API_KEY, q: "coffee" }, console.log);
126124
*/
127125
export async function getHtml<
128126
E extends EngineName = EngineName,
@@ -159,7 +157,7 @@ export async function getHtml<
159157
* @param {number=} [parameters.timeout] - timeout in milliseconds
160158
* @param {fn=} callback - optional callback
161159
* @example
162-
* const response = await getJson("google", { api_key: API_KEY, async: true, q: "coffee" });
160+
* const response = await getJson({ engine: "google", api_key: API_KEY, async: true, q: "coffee" });
163161
* const { id } = response.search_metadata;
164162
* await delay(1000); // wait for the request to be processed.
165163
*
@@ -204,7 +202,7 @@ export async function getJsonBySearchId<
204202
* @param {number=} [parameters.timeout] - timeout in milliseconds
205203
* @param {fn=} callback - optional callback
206204
* @example
207-
* const response = await getJson("google", { api_key: API_KEY, async: true, q: "coffee" });
205+
* const response = await getJson({ engine: "google", api_key: API_KEY, async: true, q: "coffee" });
208206
* const { id } = response.search_metadata;
209207
* await delay(1000); // wait for the request to be processed.
210208
*

0 commit comments

Comments
 (0)