triangle-utils 1.4.4 → 1.4.5
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.
- package/dist/src/UtilsBee.d.ts +1 -0
- package/dist/src/UtilsBee.js +12 -3
- package/package.json +1 -1
- package/src/UtilsBee.ts +14 -3
package/dist/src/UtilsBee.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare class UtilsBee {
|
|
|
2
2
|
private readonly bee;
|
|
3
3
|
private readonly text_decoder;
|
|
4
4
|
constructor(scraping_bee_api_key: string | undefined);
|
|
5
|
+
get_buffer(url: string, params?: Record<string, string | number | boolean>): Promise<Buffer<any> | undefined>;
|
|
5
6
|
get(url: string, params?: Record<string, string | number | boolean>): Promise<string | undefined>;
|
|
6
7
|
google_search(query: string, news?: boolean): Promise<Record<string, any>[] | undefined>;
|
|
7
8
|
youtube_search(query: string, options?: {}): Promise<Record<string, any>[] | undefined>;
|
package/dist/src/UtilsBee.js
CHANGED
|
@@ -6,7 +6,7 @@ export class UtilsBee {
|
|
|
6
6
|
this.bee = scraping_bee_api_key !== undefined ? new ScrapingBeeClient(scraping_bee_api_key) : undefined;
|
|
7
7
|
this.text_decoder = new TextDecoder();
|
|
8
8
|
}
|
|
9
|
-
async
|
|
9
|
+
async get_buffer(url, params = {}) {
|
|
10
10
|
if (this.bee === undefined) {
|
|
11
11
|
return undefined;
|
|
12
12
|
}
|
|
@@ -16,8 +16,10 @@ export class UtilsBee {
|
|
|
16
16
|
url: url,
|
|
17
17
|
params: params
|
|
18
18
|
});
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
if (response.data instanceof Buffer) {
|
|
20
|
+
return response.data;
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
21
23
|
}
|
|
22
24
|
catch (error) {
|
|
23
25
|
if (error instanceof Error) {
|
|
@@ -29,6 +31,13 @@ export class UtilsBee {
|
|
|
29
31
|
console.log("Failed to get from Scraping Bee, quitting.");
|
|
30
32
|
return undefined;
|
|
31
33
|
}
|
|
34
|
+
async get(url, params = {}) {
|
|
35
|
+
const buffer = await this.get_buffer(url, params);
|
|
36
|
+
if (buffer === undefined) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
return this.text_decoder.decode(buffer);
|
|
40
|
+
}
|
|
32
41
|
async google_search(query, news = false) {
|
|
33
42
|
if (this.bee === undefined) {
|
|
34
43
|
return undefined;
|
package/package.json
CHANGED
package/src/UtilsBee.ts
CHANGED
|
@@ -10,7 +10,7 @@ export class UtilsBee {
|
|
|
10
10
|
this.text_decoder = new TextDecoder()
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
async
|
|
13
|
+
async get_buffer(url : string, params : Record<string, string | number | boolean> = {}) {
|
|
14
14
|
if (this.bee === undefined) {
|
|
15
15
|
return undefined
|
|
16
16
|
}
|
|
@@ -20,8 +20,10 @@ export class UtilsBee {
|
|
|
20
20
|
url : url,
|
|
21
21
|
params : params
|
|
22
22
|
})
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if (response.data instanceof Buffer) {
|
|
24
|
+
return response.data
|
|
25
|
+
}
|
|
26
|
+
return undefined
|
|
25
27
|
} catch (error) {
|
|
26
28
|
if (error instanceof Error) {
|
|
27
29
|
console.log(error.stack)
|
|
@@ -31,6 +33,15 @@ export class UtilsBee {
|
|
|
31
33
|
}
|
|
32
34
|
console.log("Failed to get from Scraping Bee, quitting.")
|
|
33
35
|
return undefined
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async get(url : string, params : Record<string, string | number | boolean> = {}) {
|
|
40
|
+
const buffer = await this.get_buffer(url, params)
|
|
41
|
+
if (buffer === undefined) {
|
|
42
|
+
return undefined
|
|
43
|
+
}
|
|
44
|
+
return this.text_decoder.decode(buffer)
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
async google_search(query : string, news : boolean = false) : Promise<Record<string, any>[] | undefined> {
|