@crawlee/utils 4.0.0-beta.91 → 4.0.0-beta.92

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.
@@ -8,11 +8,6 @@ export declare const URL_NO_COMMAS_REGEX: RegExp;
8
8
  * Note, however, that this may prevent parsing URLs from comma delimited lists, or the URLs may become malformed.
9
9
  */
10
10
  export declare const URL_WITH_COMMAS_REGEX: RegExp;
11
- /**
12
- * Computes a weighted average of an array of numbers, complemented by an array of weights.
13
- * @ignore
14
- */
15
- export declare function weightedAvg(arrValues: number[], arrWeights: number[]): number;
16
11
  /**
17
12
  * Returns a `Promise` that resolves after a specific period of time. This is useful to implement waiting
18
13
  * in your code, e.g. to prevent overloading of target website or to avoid bot detection.
@@ -35,20 +30,3 @@ export declare function sleep(millis?: number): Promise<void>;
35
30
  * @ignore
36
31
  */
37
32
  export declare function expandShadowRoots(document: Document): string;
38
- /**
39
- * Checks if the given value is a Node.js Stream or a Web API ReadableStream.
40
- * @ignore
41
- */
42
- export declare function isStream(value: unknown): value is NodeJS.ReadableStream | ReadableStream;
43
- /**
44
- * Checks if the given value is a Node.js Buffer, ArrayBuffer, or TypedArray.
45
- * @ignore
46
- */
47
- export declare function isBuffer(value: unknown): value is Buffer | ArrayBuffer | ArrayBufferView;
48
- /**
49
- * Converts a byte-like value (Buffer, ArrayBuffer, or any typed-array / DataView) into a Buffer over
50
- * the exact same bytes, honoring `byteOffset` / `byteLength` for views. Existing Buffers are returned
51
- * as-is. Used by storage backends, which persist raw bytes regardless of the input's concrete shape.
52
- * @ignore
53
- */
54
- export declare function toBuffer(value: Buffer | ArrayBuffer | ArrayBufferView): Buffer;
@@ -9,20 +9,6 @@ export const URL_NO_COMMAS_REGEX = /https?:\/\/(www\.)?([\p{L}0-9]|[\p{L}0-9][-\
9
9
  * Note, however, that this may prevent parsing URLs from comma delimited lists, or the URLs may become malformed.
10
10
  */
11
11
  export const URL_WITH_COMMAS_REGEX = /https?:\/\/(www\.)?([\p{L}0-9]|[\p{L}0-9][-\p{L}0-9@:%._+~#=]{0,254}[\p{L}0-9])\.[a-z]{2,63}(:\d{1,5})?(\/[-\p{L}0-9@:%_+,.~#?&/=()'*]*)?/giu;
12
- /**
13
- * Computes a weighted average of an array of numbers, complemented by an array of weights.
14
- * @ignore
15
- */
16
- export function weightedAvg(arrValues, arrWeights) {
17
- const result = arrValues
18
- .map((value, i) => {
19
- const weight = arrWeights[i];
20
- const sum = value * weight;
21
- return [sum, weight];
22
- })
23
- .reduce((p, c) => [p[0] + c[0], p[1] + c[1]], [0, 0]);
24
- return result[0] / result[1];
25
- }
26
12
  /**
27
13
  * Returns a `Promise` that resolves after a specific period of time. This is useful to implement waiting
28
14
  * in your code, e.g. to prevent overloading of target website or to avoid bot detection.
@@ -71,45 +57,3 @@ export function expandShadowRoots(document) {
71
57
  replaceShadowDomsWithHtml(document.body);
72
58
  return document.documentElement.outerHTML;
73
59
  }
74
- /**
75
- * Checks if the given value is a Node.js Stream or a Web API ReadableStream.
76
- * @ignore
77
- */
78
- export function isStream(value) {
79
- if (typeof value !== 'object' || value === null) {
80
- return false;
81
- }
82
- // A Node.js Readable is both pipeable and async-iterable; a Web ReadableStream exposes pipeTo.
83
- // Requiring async-iterability for the `pipe` branch rejects plain `{ pipe }` ducks that would
84
- // otherwise blow up later in the storage backends' drain loop with a cryptic TypeError.
85
- const isNodeStream = typeof value.pipe === 'function' && typeof value[Symbol.asyncIterator] === 'function';
86
- const isWebStream = typeof value.pipeTo === 'function';
87
- return isNodeStream || isWebStream;
88
- }
89
- /**
90
- * Checks if the given value is a Node.js Buffer, ArrayBuffer, or TypedArray.
91
- * @ignore
92
- */
93
- export function isBuffer(value) {
94
- return (value != null &&
95
- typeof value === 'object' &&
96
- (Buffer.isBuffer(value) ||
97
- value instanceof ArrayBuffer ||
98
- ArrayBuffer.isView(value) ||
99
- value.constructor?.name === 'Buffer'));
100
- }
101
- /**
102
- * Converts a byte-like value (Buffer, ArrayBuffer, or any typed-array / DataView) into a Buffer over
103
- * the exact same bytes, honoring `byteOffset` / `byteLength` for views. Existing Buffers are returned
104
- * as-is. Used by storage backends, which persist raw bytes regardless of the input's concrete shape.
105
- * @ignore
106
- */
107
- export function toBuffer(value) {
108
- if (Buffer.isBuffer(value)) {
109
- return value;
110
- }
111
- if (value instanceof ArrayBuffer) {
112
- return Buffer.from(value);
113
- }
114
- return Buffer.from(value.buffer, value.byteOffset, value.byteLength);
115
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/utils",
3
- "version": "4.0.0-beta.91",
3
+ "version": "4.0.0-beta.92",
4
4
  "description": "A set of shared utilities that can be used by crawlers",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
@@ -42,8 +42,8 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@apify/ps-tree": "^1.2.0",
45
- "@crawlee/http-client": "4.0.0-beta.91",
46
- "@crawlee/types": "4.0.0-beta.91",
45
+ "@crawlee/http-client": "4.0.0-beta.92",
46
+ "@crawlee/types": "4.0.0-beta.92",
47
47
  "@types/sax": "^1.2.7",
48
48
  "cheerio": "^1.0.0",
49
49
  "domhandler": "^5.0.3",
@@ -61,5 +61,5 @@
61
61
  }
62
62
  }
63
63
  },
64
- "gitHead": "1e3e1ca10f24be53e1d527b3ea25f456baebecbf"
64
+ "gitHead": "9470e6cd2fe57b354ba30643a2348f2e737c37fe"
65
65
  }