@wdio/utils 8.12.1 → 8.14.0
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/build/envDetector.js +2 -2
- package/build/pIteration.d.ts +142 -0
- package/build/pIteration.d.ts.map +1 -0
- package/build/pIteration.js +347 -0
- package/build/shim.js +1 -1
- package/package.json +4 -5
package/build/envDetector.js
CHANGED
|
@@ -57,9 +57,9 @@ function isChrome(capabilities) {
|
|
|
57
57
|
return Boolean(capabilities.chrome || capabilities['goog:chromeOptions']);
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* check if session is run by
|
|
60
|
+
* check if session is run by Geckodriver
|
|
61
61
|
* @param {Object} capabilities caps of session response
|
|
62
|
-
* @return {Boolean} true if run by
|
|
62
|
+
* @return {Boolean} true if run by Geckodriver
|
|
63
63
|
*/
|
|
64
64
|
function isFirefox(capabilities) {
|
|
65
65
|
if (!capabilities) {
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implements ES5 [`Array#forEach()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) method.<br><br>
|
|
3
|
+
* Executes the provided callback once for each element.<br>
|
|
4
|
+
* Callbacks are run concurrently,
|
|
5
|
+
* and are only invoked for properties of the array that have been initialized (including those initialized with *undefined*), for unassigned ones `callback` is not run.<br>
|
|
6
|
+
* @param {Array} array - Array to iterate over.
|
|
7
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
8
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
9
|
+
* @return {Promise} - Returns a Promise with undefined value.
|
|
10
|
+
*/
|
|
11
|
+
export declare const forEach: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Same functionality as [`forEach()`](global.html#forEach), but runs only one callback at a time.
|
|
14
|
+
* @param {Array} array - Array to iterate over.
|
|
15
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
16
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
17
|
+
* @return {Promise} - Returns a Promise with undefined value.
|
|
18
|
+
*/
|
|
19
|
+
export declare const forEachSeries: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Implements ES5 [`Array#map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) method.<br><br>
|
|
22
|
+
* Creates a new array with the results of calling the provided callback once for each element.<br>
|
|
23
|
+
* Callbacks are run concurrently,
|
|
24
|
+
* and are only invoked for properties of the array that have been initialized (including those initialized with *undefined*), for unassigned ones`callback` is not run.<br>
|
|
25
|
+
* Resultant *Array* is always the same *length* as the original one.
|
|
26
|
+
* @param {Array} array - Array to iterate over.
|
|
27
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
28
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
29
|
+
* @return {Promise} - Returns a Promise with the resultant *Array* as value.
|
|
30
|
+
*/
|
|
31
|
+
export declare const map: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<any[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Same functionality as [`map()`](global.html#map), but runs only one callback at a time.
|
|
34
|
+
* @param {Array} array - Array to iterate over.
|
|
35
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
36
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
37
|
+
* @return {Promise} - Returns a Promise with the resultant *Array* as value.
|
|
38
|
+
*/
|
|
39
|
+
export declare const mapSeries: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<any[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Implements ES5 [`Array#find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) method.<br><br>
|
|
42
|
+
* Returns the value of the element that satisfies the provided `callback`. The value returned is the one found first.<br>
|
|
43
|
+
* Callbacks are run concurrently, meaning that all the callbacks are going to run even if the returned value is found in one of the first elements of `array`,
|
|
44
|
+
* depending on the async calls you are going to use, consider using instead [`findSeries()`](global.html#findSeries).<br>
|
|
45
|
+
* @param {Array} array - Array to iterate over.
|
|
46
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
47
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
48
|
+
* @return {Promise} - Returns a Promise with the element that passed the test as value, otherwise *undefined*.
|
|
49
|
+
*/
|
|
50
|
+
export declare const find: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<unknown>;
|
|
51
|
+
/**
|
|
52
|
+
* Same functionality as [`find()`](global.html#find), but runs only one callback at a time.
|
|
53
|
+
* @param {Array} array - Array to iterate over.
|
|
54
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
55
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
56
|
+
* @return {Promise} - Returns a Promise with the element that passed the test as value, otherwise *undefined*.
|
|
57
|
+
*/
|
|
58
|
+
export declare const findSeries: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<unknown>;
|
|
59
|
+
/**
|
|
60
|
+
* Implements ES5 [`Array#findIndex()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) method.<br><br>
|
|
61
|
+
* Returns the index of the element that satisfies the provided `callback`. The index returned is the one found first.<br>
|
|
62
|
+
* Callbacks are run concurrently, meaning that all the callbacks are going to run even if the returned index is found in one of the first elements of `array`,
|
|
63
|
+
* depending on the async calls you are going to use, consider using instead [`findSeries()`](global.html#findSeries).<br>
|
|
64
|
+
* @param {Array} array - Array to iterate over.
|
|
65
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
66
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
67
|
+
* @return {Promise} - Returns a Promise with the index that passed the test as value, otherwise *-1*.
|
|
68
|
+
*/
|
|
69
|
+
export declare const findIndex: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<unknown>;
|
|
70
|
+
/**
|
|
71
|
+
* Same functionality as [`findIndex()`](global.html#findIndex), but runs only one callback at a time.
|
|
72
|
+
* @param {Array} array - Array to iterate over.
|
|
73
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
74
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
75
|
+
* @return {Promise} - Returns a Promise with the index that passed the test, otherwise *-1*.
|
|
76
|
+
*/
|
|
77
|
+
export declare const findIndexSeries: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<number | undefined>;
|
|
78
|
+
/**
|
|
79
|
+
* Implements ES5 [`Array#some()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) method.<br><br>
|
|
80
|
+
* Test if some element in `array` passes the test implemented in `callback`.<br>
|
|
81
|
+
* Callbacks are run concurrently, meaning that all the callbacks are going to run even if some of the first elements pass the test,
|
|
82
|
+
* depending on the async calls you are going to use, consider using instead [`someSeries()`](global.html#someSeries).<br>
|
|
83
|
+
* @param {Array} array - Array to iterate over.
|
|
84
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
85
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
86
|
+
* @return {Promise} - Returns a Promise with *true* as value if some element passed the test, otherwise *false*.
|
|
87
|
+
*/
|
|
88
|
+
export declare const some: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<unknown>;
|
|
89
|
+
/**
|
|
90
|
+
* Same functionality as [`some()`](global.html#some), but runs only one callback at a time.
|
|
91
|
+
* @param {Array} array - Array to iterate over.
|
|
92
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
93
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
94
|
+
* @return {Promise} - Returns a Promise with *true* as value if some element passed the test, otherwise *false*.
|
|
95
|
+
*/
|
|
96
|
+
export declare const someSeries: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<boolean>;
|
|
97
|
+
/**
|
|
98
|
+
* Implements ES5 [`Array#every()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) method.<br><br>
|
|
99
|
+
* Test if all elements in `array` pass the test implemented in `callback`.<br>
|
|
100
|
+
* Callbacks are run concurrently, meaning that all the callbacks are going to run even if any of the first elements do not pass the test,
|
|
101
|
+
* depending on the async calls you are going to use, consider using instead [`everySeries()`](global.html#everySeries).<br>
|
|
102
|
+
* @param {Array} array - Array to iterate over.
|
|
103
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
104
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
105
|
+
* @return {Promise} - Returns a Promise with *true* as value if all elements passed the test, otherwise *false*.
|
|
106
|
+
*/
|
|
107
|
+
export declare const every: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<unknown>;
|
|
108
|
+
/**
|
|
109
|
+
* Same functionality as [`every()`](global.html#every), but runs only one callback at a time.<br><br>
|
|
110
|
+
* @param {Array} array - Array to iterate over.
|
|
111
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
112
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
113
|
+
* @return {Promise} - Returns a Promise with *true* as value if all elements passed the test, otherwise *false*.
|
|
114
|
+
*/
|
|
115
|
+
export declare const everySeries: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<boolean>;
|
|
116
|
+
/**
|
|
117
|
+
* Implements ES5 [`Array#filter()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) method.<br><br>
|
|
118
|
+
* Creates a new array with the elements that passed the test implemented in `callback`.<br>
|
|
119
|
+
* Callbacks are run concurrently.<br>
|
|
120
|
+
* @param {Array} array - Array to iterate over.
|
|
121
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
122
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
123
|
+
* @return {Promise} - Returns a Promise with the resultant filtered *Array* as value.
|
|
124
|
+
*/
|
|
125
|
+
export declare const filter: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<unknown>;
|
|
126
|
+
/**
|
|
127
|
+
* Same functionality as [`filter()`](global.html#filter), but runs only one callback at a time.
|
|
128
|
+
* @param {Array} array - Array to iterate over.
|
|
129
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
130
|
+
* @return {Promise} - Returns a Promise with the resultant filtered *Array* as value.
|
|
131
|
+
*/
|
|
132
|
+
export declare const filterSeries: (array: unknown[], callback: Function, thisArg?: unknown) => Promise<unknown[]>;
|
|
133
|
+
/**
|
|
134
|
+
* Implements ES5 [`Array#reduce()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce) method.<br><br>
|
|
135
|
+
* Applies a `callback` against an accumulator and each element in `array`.
|
|
136
|
+
* @param {Array} array - Array to iterate over.
|
|
137
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts four arguments: `accumulator`, `currentValue`, `currentIndex` and `array`.
|
|
138
|
+
* @param {Object} [initialValue] - Used as first argument to the first call of `callback`.
|
|
139
|
+
* @return {Promise} - Returns a Promise with the resultant value from the reduction.
|
|
140
|
+
*/
|
|
141
|
+
export declare const reduce: (array: unknown[], callback: Function, initialValue?: unknown) => Promise<any>;
|
|
142
|
+
//# sourceMappingURL=pIteration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pIteration.d.ts","sourceRoot":"","sources":["../src/pIteration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO,UAAiB,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,kBAWpF,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,UAAiB,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,kBAM1F,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,GAAG,UAAiB,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,mBAUhF,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,UAAiB,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,mBAQtF,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,IAAI,UAAW,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,qBAqB3E,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,UAAiB,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,qBAMvF,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,UAAW,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,qBAqBhF,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,UAAiB,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,gCAM5F,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,IAAI,UAAW,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,qBAyB3E,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,UAAiB,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,qBAOvF,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,KAAK,UAAW,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,qBAyB5E,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,UAAiB,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,qBAOxF,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,UAAW,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,qBAwB7E,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,UAAiB,OAAO,EAAE,YAAY,QAAQ,YAAY,OAAO,uBAQzF,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,UAAiB,OAAO,EAAE,YAAY,QAAQ,iBAAiB,OAAO,iBAmBxF,CAAA"}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Implements ES5 [`Array#forEach()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) method.<br><br>
|
|
3
|
+
* Executes the provided callback once for each element.<br>
|
|
4
|
+
* Callbacks are run concurrently,
|
|
5
|
+
* and are only invoked for properties of the array that have been initialized (including those initialized with *undefined*), for unassigned ones `callback` is not run.<br>
|
|
6
|
+
* @param {Array} array - Array to iterate over.
|
|
7
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
8
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
9
|
+
* @return {Promise} - Returns a Promise with undefined value.
|
|
10
|
+
*/
|
|
11
|
+
export const forEach = async (array, callback, thisArg) => {
|
|
12
|
+
const promiseArray = [];
|
|
13
|
+
for (let i = 0; i < array.length; i++) {
|
|
14
|
+
if (i in array) {
|
|
15
|
+
const p = Promise.resolve(array[i]).then((currentValue) => {
|
|
16
|
+
return callback.call(thisArg || this, currentValue, i, array);
|
|
17
|
+
});
|
|
18
|
+
promiseArray.push(p);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
await Promise.all(promiseArray);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Same functionality as [`forEach()`](global.html#forEach), but runs only one callback at a time.
|
|
25
|
+
* @param {Array} array - Array to iterate over.
|
|
26
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
27
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
28
|
+
* @return {Promise} - Returns a Promise with undefined value.
|
|
29
|
+
*/
|
|
30
|
+
export const forEachSeries = async (array, callback, thisArg) => {
|
|
31
|
+
for (let i = 0; i < array.length; i++) {
|
|
32
|
+
if (i in array) {
|
|
33
|
+
await callback.call(thisArg || this, await array[i], i, array);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Implements ES5 [`Array#map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) method.<br><br>
|
|
39
|
+
* Creates a new array with the results of calling the provided callback once for each element.<br>
|
|
40
|
+
* Callbacks are run concurrently,
|
|
41
|
+
* and are only invoked for properties of the array that have been initialized (including those initialized with *undefined*), for unassigned ones`callback` is not run.<br>
|
|
42
|
+
* Resultant *Array* is always the same *length* as the original one.
|
|
43
|
+
* @param {Array} array - Array to iterate over.
|
|
44
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
45
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
46
|
+
* @return {Promise} - Returns a Promise with the resultant *Array* as value.
|
|
47
|
+
*/
|
|
48
|
+
export const map = async (array, callback, thisArg) => {
|
|
49
|
+
const promiseArray = [];
|
|
50
|
+
for (let i = 0; i < array.length; i++) {
|
|
51
|
+
if (i in array) {
|
|
52
|
+
promiseArray[i] = Promise.resolve(array[i]).then((currentValue) => {
|
|
53
|
+
return callback.call(thisArg || this, currentValue, i, array);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return Promise.all(promiseArray);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Same functionality as [`map()`](global.html#map), but runs only one callback at a time.
|
|
61
|
+
* @param {Array} array - Array to iterate over.
|
|
62
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
63
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
64
|
+
* @return {Promise} - Returns a Promise with the resultant *Array* as value.
|
|
65
|
+
*/
|
|
66
|
+
export const mapSeries = async (array, callback, thisArg) => {
|
|
67
|
+
const result = [];
|
|
68
|
+
for (let i = 0; i < array.length; i++) {
|
|
69
|
+
if (i in array) {
|
|
70
|
+
result[i] = await callback.call(thisArg || this, await array[i], i, array);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Implements ES5 [`Array#find()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find) method.<br><br>
|
|
77
|
+
* Returns the value of the element that satisfies the provided `callback`. The value returned is the one found first.<br>
|
|
78
|
+
* Callbacks are run concurrently, meaning that all the callbacks are going to run even if the returned value is found in one of the first elements of `array`,
|
|
79
|
+
* depending on the async calls you are going to use, consider using instead [`findSeries()`](global.html#findSeries).<br>
|
|
80
|
+
* @param {Array} array - Array to iterate over.
|
|
81
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
82
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
83
|
+
* @return {Promise} - Returns a Promise with the element that passed the test as value, otherwise *undefined*.
|
|
84
|
+
*/
|
|
85
|
+
export const find = (array, callback, thisArg) => {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
if (array.length === 0) {
|
|
88
|
+
return resolve(undefined);
|
|
89
|
+
}
|
|
90
|
+
let counter = 1;
|
|
91
|
+
for (let i = 0; i < array.length; i++) {
|
|
92
|
+
const check = (found) => {
|
|
93
|
+
if (found) {
|
|
94
|
+
resolve(array[i]);
|
|
95
|
+
}
|
|
96
|
+
else if (counter === array.length) {
|
|
97
|
+
resolve(undefined);
|
|
98
|
+
}
|
|
99
|
+
counter++;
|
|
100
|
+
};
|
|
101
|
+
Promise.resolve(array[i])
|
|
102
|
+
.then((elem) => callback.call(thisArg || this, elem, i, array))
|
|
103
|
+
.then(check)
|
|
104
|
+
.catch(reject);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Same functionality as [`find()`](global.html#find), but runs only one callback at a time.
|
|
110
|
+
* @param {Array} array - Array to iterate over.
|
|
111
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
112
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
113
|
+
* @return {Promise} - Returns a Promise with the element that passed the test as value, otherwise *undefined*.
|
|
114
|
+
*/
|
|
115
|
+
export const findSeries = async (array, callback, thisArg) => {
|
|
116
|
+
for (let i = 0; i < array.length; i++) {
|
|
117
|
+
if (await callback.call(thisArg || this, await array[i], i, array)) {
|
|
118
|
+
return array[i];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Implements ES5 [`Array#findIndex()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) method.<br><br>
|
|
124
|
+
* Returns the index of the element that satisfies the provided `callback`. The index returned is the one found first.<br>
|
|
125
|
+
* Callbacks are run concurrently, meaning that all the callbacks are going to run even if the returned index is found in one of the first elements of `array`,
|
|
126
|
+
* depending on the async calls you are going to use, consider using instead [`findSeries()`](global.html#findSeries).<br>
|
|
127
|
+
* @param {Array} array - Array to iterate over.
|
|
128
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
129
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
130
|
+
* @return {Promise} - Returns a Promise with the index that passed the test as value, otherwise *-1*.
|
|
131
|
+
*/
|
|
132
|
+
export const findIndex = (array, callback, thisArg) => {
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
if (array.length === 0) {
|
|
135
|
+
return resolve(-1);
|
|
136
|
+
}
|
|
137
|
+
let counter = 1;
|
|
138
|
+
for (let i = 0; i < array.length; i++) {
|
|
139
|
+
const check = (found) => {
|
|
140
|
+
if (found) {
|
|
141
|
+
resolve(i);
|
|
142
|
+
}
|
|
143
|
+
else if (counter === array.length) {
|
|
144
|
+
resolve(-1);
|
|
145
|
+
}
|
|
146
|
+
counter++;
|
|
147
|
+
};
|
|
148
|
+
Promise.resolve(array[i])
|
|
149
|
+
.then((elem) => callback.call(thisArg || this, elem, i, array))
|
|
150
|
+
.then(check)
|
|
151
|
+
.catch(reject);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Same functionality as [`findIndex()`](global.html#findIndex), but runs only one callback at a time.
|
|
157
|
+
* @param {Array} array - Array to iterate over.
|
|
158
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
159
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
160
|
+
* @return {Promise} - Returns a Promise with the index that passed the test, otherwise *-1*.
|
|
161
|
+
*/
|
|
162
|
+
export const findIndexSeries = async (array, callback, thisArg) => {
|
|
163
|
+
for (let i = 0; i < array.length; i++) {
|
|
164
|
+
if (await callback.call(thisArg || this, await array[i], i, array)) {
|
|
165
|
+
return i;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Implements ES5 [`Array#some()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) method.<br><br>
|
|
171
|
+
* Test if some element in `array` passes the test implemented in `callback`.<br>
|
|
172
|
+
* Callbacks are run concurrently, meaning that all the callbacks are going to run even if some of the first elements pass the test,
|
|
173
|
+
* depending on the async calls you are going to use, consider using instead [`someSeries()`](global.html#someSeries).<br>
|
|
174
|
+
* @param {Array} array - Array to iterate over.
|
|
175
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
176
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
177
|
+
* @return {Promise} - Returns a Promise with *true* as value if some element passed the test, otherwise *false*.
|
|
178
|
+
*/
|
|
179
|
+
export const some = (array, callback, thisArg) => {
|
|
180
|
+
return new Promise((resolve, reject) => {
|
|
181
|
+
if (array.length === 0) {
|
|
182
|
+
return resolve(false);
|
|
183
|
+
}
|
|
184
|
+
let counter = 1;
|
|
185
|
+
for (let i = 0; i < array.length; i++) {
|
|
186
|
+
if (!(i in array)) {
|
|
187
|
+
counter++;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const check = (found) => {
|
|
191
|
+
if (found) {
|
|
192
|
+
resolve(true);
|
|
193
|
+
}
|
|
194
|
+
else if (counter === array.length) {
|
|
195
|
+
resolve(false);
|
|
196
|
+
}
|
|
197
|
+
counter++;
|
|
198
|
+
};
|
|
199
|
+
Promise.resolve(array[i])
|
|
200
|
+
.then((elem) => callback.call(thisArg || this, elem, i, array))
|
|
201
|
+
.then(check)
|
|
202
|
+
.catch(reject);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Same functionality as [`some()`](global.html#some), but runs only one callback at a time.
|
|
208
|
+
* @param {Array} array - Array to iterate over.
|
|
209
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
210
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
211
|
+
* @return {Promise} - Returns a Promise with *true* as value if some element passed the test, otherwise *false*.
|
|
212
|
+
*/
|
|
213
|
+
export const someSeries = async (array, callback, thisArg) => {
|
|
214
|
+
for (let i = 0; i < array.length; i++) {
|
|
215
|
+
if (i in array && await callback.call(thisArg || this, await array[i], i, array)) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return false;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Implements ES5 [`Array#every()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) method.<br><br>
|
|
223
|
+
* Test if all elements in `array` pass the test implemented in `callback`.<br>
|
|
224
|
+
* Callbacks are run concurrently, meaning that all the callbacks are going to run even if any of the first elements do not pass the test,
|
|
225
|
+
* depending on the async calls you are going to use, consider using instead [`everySeries()`](global.html#everySeries).<br>
|
|
226
|
+
* @param {Array} array - Array to iterate over.
|
|
227
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
228
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
229
|
+
* @return {Promise} - Returns a Promise with *true* as value if all elements passed the test, otherwise *false*.
|
|
230
|
+
*/
|
|
231
|
+
export const every = (array, callback, thisArg) => {
|
|
232
|
+
return new Promise((resolve, reject) => {
|
|
233
|
+
if (array.length === 0) {
|
|
234
|
+
return resolve(true);
|
|
235
|
+
}
|
|
236
|
+
let counter = 1;
|
|
237
|
+
for (let i = 0; i < array.length; i++) {
|
|
238
|
+
if (!(i in array)) {
|
|
239
|
+
counter++;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
const check = (found) => {
|
|
243
|
+
if (!found) {
|
|
244
|
+
resolve(false);
|
|
245
|
+
}
|
|
246
|
+
else if (counter === array.length) {
|
|
247
|
+
resolve(true);
|
|
248
|
+
}
|
|
249
|
+
counter++;
|
|
250
|
+
};
|
|
251
|
+
Promise.resolve(array[i])
|
|
252
|
+
.then((elem) => callback.call(thisArg || this, elem, i, array))
|
|
253
|
+
.then(check)
|
|
254
|
+
.catch(reject);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Same functionality as [`every()`](global.html#every), but runs only one callback at a time.<br><br>
|
|
260
|
+
* @param {Array} array - Array to iterate over.
|
|
261
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
262
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
263
|
+
* @return {Promise} - Returns a Promise with *true* as value if all elements passed the test, otherwise *false*.
|
|
264
|
+
*/
|
|
265
|
+
export const everySeries = async (array, callback, thisArg) => {
|
|
266
|
+
for (let i = 0; i < array.length; i++) {
|
|
267
|
+
if (i in array && !await callback.call(thisArg || this, await array[i], i, array)) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return true;
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Implements ES5 [`Array#filter()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) method.<br><br>
|
|
275
|
+
* Creates a new array with the elements that passed the test implemented in `callback`.<br>
|
|
276
|
+
* Callbacks are run concurrently.<br>
|
|
277
|
+
* @param {Array} array - Array to iterate over.
|
|
278
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
279
|
+
* @param {Object} [thisArg] - Value to use as *this* when executing the `callback`.
|
|
280
|
+
* @return {Promise} - Returns a Promise with the resultant filtered *Array* as value.
|
|
281
|
+
*/
|
|
282
|
+
export const filter = (array, callback, thisArg) => {
|
|
283
|
+
/* two loops are necessary in order to do the filtering concurrently
|
|
284
|
+
* while keeping the order of the elements
|
|
285
|
+
* (if you find a better way to do it please send a PR!)
|
|
286
|
+
*/
|
|
287
|
+
return new Promise((resolve, reject) => {
|
|
288
|
+
const promiseArray = [];
|
|
289
|
+
for (let i = 0; i < array.length; i++) {
|
|
290
|
+
if (i in array) {
|
|
291
|
+
promiseArray[i] = Promise.resolve(array[i]).then((currentValue) => {
|
|
292
|
+
return callback.call(thisArg || this, currentValue, i, array);
|
|
293
|
+
}).catch(reject);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return Promise.all(promiseArray.map(async (p, i) => {
|
|
297
|
+
if (await p) {
|
|
298
|
+
return await array[i];
|
|
299
|
+
}
|
|
300
|
+
return undefined;
|
|
301
|
+
})).then((result) => result.filter((val) => typeof val !== 'undefined')).then(resolve, reject);
|
|
302
|
+
});
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Same functionality as [`filter()`](global.html#filter), but runs only one callback at a time.
|
|
306
|
+
* @param {Array} array - Array to iterate over.
|
|
307
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts three arguments: `currentValue`, `index` and `array`.
|
|
308
|
+
* @return {Promise} - Returns a Promise with the resultant filtered *Array* as value.
|
|
309
|
+
*/
|
|
310
|
+
export const filterSeries = async (array, callback, thisArg) => {
|
|
311
|
+
const result = [];
|
|
312
|
+
for (let i = 0; i < array.length; i++) {
|
|
313
|
+
if (i in array && await callback.call(thisArg || this, await array[i], i, array)) {
|
|
314
|
+
result.push(await array[i]);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return result;
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* Implements ES5 [`Array#reduce()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce) method.<br><br>
|
|
321
|
+
* Applies a `callback` against an accumulator and each element in `array`.
|
|
322
|
+
* @param {Array} array - Array to iterate over.
|
|
323
|
+
* @param {Function} callback - Function to apply each item in `array`. Accepts four arguments: `accumulator`, `currentValue`, `currentIndex` and `array`.
|
|
324
|
+
* @param {Object} [initialValue] - Used as first argument to the first call of `callback`.
|
|
325
|
+
* @return {Promise} - Returns a Promise with the resultant value from the reduction.
|
|
326
|
+
*/
|
|
327
|
+
export const reduce = async (array, callback, initialValue) => {
|
|
328
|
+
if (array.length === 0 && initialValue === undefined) {
|
|
329
|
+
throw TypeError('Reduce of empty array with no initial value');
|
|
330
|
+
}
|
|
331
|
+
let i;
|
|
332
|
+
let previousValue;
|
|
333
|
+
if (initialValue !== undefined) {
|
|
334
|
+
previousValue = initialValue;
|
|
335
|
+
i = 0;
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
previousValue = array[0];
|
|
339
|
+
i = 1;
|
|
340
|
+
}
|
|
341
|
+
for (i; i < array.length; i++) {
|
|
342
|
+
if (i in array) {
|
|
343
|
+
previousValue = await callback(await previousValue, await array[i], i, array);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return previousValue;
|
|
347
|
+
};
|
package/build/shim.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wdio/utils",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.14.0",
|
|
4
4
|
"description": "A WDIO helper utility to provide several utility functions used across the project.",
|
|
5
5
|
"author": "Christian Bromann <mail@bromann.dev>",
|
|
6
6
|
"homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-utils",
|
|
@@ -31,12 +31,11 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@wdio/logger": "8.11.0",
|
|
34
|
-
"@wdio/types": "8.
|
|
35
|
-
"import-meta-resolve": "^3.0.0"
|
|
36
|
-
"p-iteration": "^1.1.8"
|
|
34
|
+
"@wdio/types": "8.14.0",
|
|
35
|
+
"import-meta-resolve": "^3.0.0"
|
|
37
36
|
},
|
|
38
37
|
"publishConfig": {
|
|
39
38
|
"access": "public"
|
|
40
39
|
},
|
|
41
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "cb2092b007e6d2ac23a49aa30dae67d70e45906d"
|
|
42
41
|
}
|