Skip to content

Commit dc80601

Browse files
committed
chore: reduce number of dependencies of utilities package
1 parent 56ffab3 commit dc80601

File tree

5 files changed

+10
-71
lines changed

5 files changed

+10
-71
lines changed

package-lock.json

Lines changed: 3 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"lint-staged": {
4848
"*.ts": [
49-
"eslint packages/*/src --fix"
49+
"eslint packages/*/src/**/*.ts --fix"
5050
]
5151
},
5252
"devDependencies": {

packages/utilities/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,9 @@
4949
"ajv": "^6.12.6",
5050
"countries-list": "^2.6.1",
5151
"create-hmac": "^1.1.7",
52-
"cherow": "^1.6.9",
53-
"is-buffer": "^2.0.5",
54-
"request": "^2.88.2"
52+
"cherow": "^1.6.9"
5553
},
5654
"devDependencies": {
57-
"@types/create-hmac": "^1.1.0",
58-
"@types/request": "^2.48.5"
55+
"@types/create-hmac": "^1.1.0"
5956
}
6057
}

packages/utilities/src/utilities.client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*
77
*/
88

9-
import isBuffer from 'is-buffer';
109
import { countries } from 'countries-list';
1110
import { VERSION_INT_MAJOR_BASE, VERSION_INT_MINOR_BASE, PROXY_URL_REGEX, URL_REGEX, RELATIVE_URL_REGEX } from '@apify/consts';
1211
import { m, parseAjvError } from '@apify/input_schema';
@@ -19,6 +18,10 @@ export function isNullOrUndefined(obj: unknown): boolean {
1918
return obj == null;
2019
}
2120

21+
export function isBuffer(obj: any): boolean {
22+
return obj != null && obj.constructor != null && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj);
23+
}
24+
2225
/**
2326
* Converts Date object to ISO string.
2427
*/

packages/utilities/src/utilities.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
import crypto from 'crypto';
11-
import request, { CoreOptions, Response } from 'request';
1211
import log, { Logger, LoggerJson, LogLevel } from '@apify/log';
1312
import { ANONYMOUS_USERNAME } from '@apify/consts';
1413

@@ -190,31 +189,6 @@ export function weightedAverage(val1: number, weight1: number, val2: number, wei
190189
return (val1 * weight1 + val2 * weight2) / (weight1 + weight2);
191190
}
192191

193-
/**
194-
* Promised version of request() library.
195-
* @param opts Options object for request() function.
196-
* @param failOnHttpError If true-ish, the function rejects the promise
197-
* if HTTP status is in the range 4XX or 5XX.
198-
* @return
199-
*/
200-
export function requestPromised(opts: CoreOptions, failOnHttpError?: boolean): Promise<any> {
201-
// TODO: Add unit test for this !!!
202-
// (edit: better to get rid of deprecated `request` and pick something with promise support baked in)
203-
return new Promise(((resolve, reject) => {
204-
request(opts as any, (error: Error, response: Response, body: any) => {
205-
if (error) return reject(error);
206-
if (failOnHttpError && response.statusCode >= 400 && response.statusCode <= 599) {
207-
const err = new Error(`Received HTTP error response status ${response.statusCode}`) as any;
208-
err.statusCode = response.statusCode;
209-
err.body = body;
210-
211-
return reject(err);
212-
}
213-
resolve({ body, response, statusCode: response.statusCode });
214-
});
215-
}));
216-
}
217-
218192
/**
219193
* List of forbidden usernames. Note that usernames can be used as apify.com/username,
220194
* so we need to prohibit any username that might be part of our website or confusing in anyway.

0 commit comments

Comments
 (0)