@stdlib/utils-async-none-by-right 0.0.8 → 0.2.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/LICENSE +0 -304
- package/NOTICE +1 -1
- package/README.md +69 -47
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +19 -24
- package/lib/factory.js +4 -4
- package/lib/index.js +3 -3
- package/lib/{none_by_right.js → main.js} +0 -1
- package/lib/validate.js +4 -3
- package/package.json +20 -17
- package/docs/repl.txt +0 -209
- package/docs/types/test.ts +0 -156
package/docs/types/index.d.ts
CHANGED
|
@@ -16,16 +16,16 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
// TypeScript Version:
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
20
|
|
|
21
21
|
/// <reference types="@stdlib/types"/>
|
|
22
22
|
|
|
23
|
-
import { Collection } from '@stdlib/types/
|
|
23
|
+
import { Collection } from '@stdlib/types/array';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Interface defining function options.
|
|
27
27
|
*/
|
|
28
|
-
interface Options {
|
|
28
|
+
interface Options<T, V> {
|
|
29
29
|
/**
|
|
30
30
|
* The maximum number of pending invocations at any one time.
|
|
31
31
|
*/
|
|
@@ -39,7 +39,7 @@ interface Options {
|
|
|
39
39
|
/**
|
|
40
40
|
* Execution context.
|
|
41
41
|
*/
|
|
42
|
-
thisArg?:
|
|
42
|
+
thisArg?: ThisParameterType<Predicate<T, V>>;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
@@ -76,7 +76,7 @@ type Callback = Nullary | Unary | Binary;
|
|
|
76
76
|
* @param value - collection value
|
|
77
77
|
* @param next - callback which should be called once the predicate function has finished processing a collection value
|
|
78
78
|
*/
|
|
79
|
-
type BinaryPredicate = ( value:
|
|
79
|
+
type BinaryPredicate<T, V> = ( this: V, value: T, next: Callback ) => void;
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* Checks whether an element in a collection passes a test.
|
|
@@ -85,7 +85,7 @@ type BinaryPredicate = ( value: any, next: Callback ) => void;
|
|
|
85
85
|
* @param index - collection index
|
|
86
86
|
* @param next - callback which should be called once the `predicate` function has finished processing a collection `value`
|
|
87
87
|
*/
|
|
88
|
-
type TernaryPredicate = ( value:
|
|
88
|
+
type TernaryPredicate<T, V> = ( this: V, value: T, index: number, next: Callback ) => void;
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
91
|
* Checks whether an element in a collection passes a test.
|
|
@@ -95,7 +95,7 @@ type TernaryPredicate = ( value: any, index: number, next: Callback ) => void;
|
|
|
95
95
|
* @param collection - input collection
|
|
96
96
|
* @param next - callback which should be called once the `predicate` function has finished processing a collection `value`
|
|
97
97
|
*/
|
|
98
|
-
type QuaternaryPredicate = ( value:
|
|
98
|
+
type QuaternaryPredicate<T, V> = ( this: V, value: T, index: number, collection: Collection<T>, next: Callback ) => void;
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* Checks whether an element in a collection passes a test.
|
|
@@ -105,15 +105,15 @@ type QuaternaryPredicate = ( value: any, index: number, collection: Collection,
|
|
|
105
105
|
* @param collection - input collection
|
|
106
106
|
* @param next - callback which should be called once the `predicate` function has finished processing a collection `value`
|
|
107
107
|
*/
|
|
108
|
-
type Predicate = BinaryPredicate | TernaryPredicate | QuaternaryPredicate
|
|
108
|
+
type Predicate<T, V> = BinaryPredicate<T, V> | TernaryPredicate<T, V> | QuaternaryPredicate<T, V>;
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
* Tests whether all elements in a collection fail a test implemented by a predicate function
|
|
111
|
+
* Tests whether all elements in a collection fail a test implemented by a predicate function.
|
|
112
112
|
*
|
|
113
113
|
* @param collection - input collection
|
|
114
114
|
* @param done - function to invoke upon completion
|
|
115
115
|
*/
|
|
116
|
-
type FactoryFunction = ( collection: Collection
|
|
116
|
+
type FactoryFunction<T> = ( collection: Collection<T>, done: Callback ) => void;
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
119
|
* Interface for `noneByRightAsync`.
|
|
@@ -127,7 +127,6 @@ interface NoneByRightAsync {
|
|
|
127
127
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
128
128
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
|
|
129
129
|
*
|
|
130
|
-
*
|
|
131
130
|
* @param collection - input collection
|
|
132
131
|
* @param options - function options
|
|
133
132
|
* @param options.thisArg - execution context
|
|
@@ -138,7 +137,7 @@ interface NoneByRightAsync {
|
|
|
138
137
|
* @throws must provide valid options
|
|
139
138
|
*
|
|
140
139
|
* @example
|
|
141
|
-
* var readFile = require(
|
|
140
|
+
* var readFile = require( '@stdlib/fs-read-file' );
|
|
142
141
|
*
|
|
143
142
|
* function done( error, bool ) {
|
|
144
143
|
* if ( error ) {
|
|
@@ -172,7 +171,7 @@ interface NoneByRightAsync {
|
|
|
172
171
|
*
|
|
173
172
|
* noneByRightAsync( files, predicate, done );
|
|
174
173
|
*/
|
|
175
|
-
( collection: Collection
|
|
174
|
+
<T = unknown, V = unknown>( collection: Collection<T>, options: Options<T, V>, predicate: Predicate<T, V>, done: Callback ): void;
|
|
176
175
|
|
|
177
176
|
/**
|
|
178
177
|
* Tests whether all elements in a collection fail a test implemented by a predicate function, iterating from right to left.
|
|
@@ -182,13 +181,12 @@ interface NoneByRightAsync {
|
|
|
182
181
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
183
182
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
|
|
184
183
|
*
|
|
185
|
-
*
|
|
186
184
|
* @param collection - input collection
|
|
187
185
|
* @param predicate - predicate function to invoke for each element in a collection
|
|
188
186
|
* @param done - function to invoke upon completion
|
|
189
187
|
*
|
|
190
188
|
* @example
|
|
191
|
-
* var readFile = require(
|
|
189
|
+
* var readFile = require( '@stdlib/fs-read-file' );
|
|
192
190
|
*
|
|
193
191
|
* function done( error, bool ) {
|
|
194
192
|
* if ( error ) {
|
|
@@ -222,7 +220,7 @@ interface NoneByRightAsync {
|
|
|
222
220
|
*
|
|
223
221
|
* noneByRightAsync( files, predicate, done );
|
|
224
222
|
*/
|
|
225
|
-
( collection: Collection
|
|
223
|
+
<T = unknown, V = unknown>( collection: Collection<T>, predicate: Predicate<T, V>, done: Callback ): void;
|
|
226
224
|
|
|
227
225
|
/**
|
|
228
226
|
* Returns a function for testing whether all elements in a collection fail a test implemented by a predicate function, iterating from right to left.
|
|
@@ -232,7 +230,6 @@ interface NoneByRightAsync {
|
|
|
232
230
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
233
231
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
|
|
234
232
|
*
|
|
235
|
-
*
|
|
236
233
|
* @param options - function options
|
|
237
234
|
* @param options.thisArg - execution context
|
|
238
235
|
* @param options.limit - maximum number of pending invocations at any one time
|
|
@@ -243,7 +240,7 @@ interface NoneByRightAsync {
|
|
|
243
240
|
* @returns function which invokes the predicate function once for each element in a collection
|
|
244
241
|
*
|
|
245
242
|
* @example
|
|
246
|
-
* var readFile = require(
|
|
243
|
+
* var readFile = require( '@stdlib/fs-read-file' );
|
|
247
244
|
*
|
|
248
245
|
* function predicate( file, next ) {
|
|
249
246
|
* var opts = {
|
|
@@ -287,7 +284,7 @@ interface NoneByRightAsync {
|
|
|
287
284
|
* // Try to read each element in `files`:
|
|
288
285
|
* noneByRightAsync( files, done );
|
|
289
286
|
*/
|
|
290
|
-
factory( options: Options, predicate: Predicate ): FactoryFunction
|
|
287
|
+
factory<T = unknown, V = unknown>( options: Options<T, V>, predicate: Predicate<T, V> ): FactoryFunction<T>;
|
|
291
288
|
|
|
292
289
|
/**
|
|
293
290
|
* Returns a function for testing whether all elements in a collection fail a test implemented by a predicate function, iterating from right to left.
|
|
@@ -297,14 +294,13 @@ interface NoneByRightAsync {
|
|
|
297
294
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
298
295
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
|
|
299
296
|
*
|
|
300
|
-
*
|
|
301
297
|
* @param predicate - predicate function to invoke for each element in a collection
|
|
302
298
|
* @param done - function to invoke upon completion
|
|
303
299
|
* @throws must provide valid options
|
|
304
300
|
* @returns function which invokes the predicate function once for each element in a collection
|
|
305
301
|
*
|
|
306
302
|
* @example
|
|
307
|
-
* var readFile = require(
|
|
303
|
+
* var readFile = require( '@stdlib/fs-read-file' );
|
|
308
304
|
*
|
|
309
305
|
* function predicate( file, next ) {
|
|
310
306
|
* var opts = {
|
|
@@ -343,7 +339,7 @@ interface NoneByRightAsync {
|
|
|
343
339
|
* // Try to read each element in `files`:
|
|
344
340
|
* noneByRightAsync( files, done );
|
|
345
341
|
*/
|
|
346
|
-
factory( predicate: Predicate ): FactoryFunction
|
|
342
|
+
factory<T = unknown, V = unknown>( predicate: Predicate<T, V> ): FactoryFunction<T>;
|
|
347
343
|
}
|
|
348
344
|
|
|
349
345
|
/**
|
|
@@ -354,7 +350,6 @@ interface NoneByRightAsync {
|
|
|
354
350
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
355
351
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
|
|
356
352
|
*
|
|
357
|
-
*
|
|
358
353
|
* @param collection - input collection
|
|
359
354
|
* @param options - function options
|
|
360
355
|
* @param options.thisArg - execution context
|
|
@@ -365,7 +360,7 @@ interface NoneByRightAsync {
|
|
|
365
360
|
* @throws must provide valid options
|
|
366
361
|
*
|
|
367
362
|
* @example
|
|
368
|
-
* var readFile = require(
|
|
363
|
+
* var readFile = require( '@stdlib/fs-read-file' );
|
|
369
364
|
*
|
|
370
365
|
* function done( error, bool ) {
|
|
371
366
|
* if ( error ) {
|
package/lib/factory.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
var isFunction = require( '@stdlib/assert-is-function' );
|
|
24
24
|
var isCollection = require( '@stdlib/assert-is-collection' );
|
|
25
|
+
var format = require( '@stdlib/string-format' );
|
|
25
26
|
var PINF = require( '@stdlib/constants-float64-pinf' );
|
|
26
27
|
var validate = require( './validate.js' );
|
|
27
28
|
var limit = require( './limit.js' );
|
|
@@ -37,7 +38,6 @@ var limit = require( './limit.js' );
|
|
|
37
38
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
38
39
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
|
|
39
40
|
*
|
|
40
|
-
*
|
|
41
41
|
* @param {Options} [options] - function options
|
|
42
42
|
* @param {*} [options.thisArg] - execution context
|
|
43
43
|
* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time
|
|
@@ -109,7 +109,7 @@ function factory( options, predicate ) {
|
|
|
109
109
|
f = options;
|
|
110
110
|
}
|
|
111
111
|
if ( !isFunction( f ) ) {
|
|
112
|
-
throw new TypeError( 'invalid argument. Last argument must be a function. Value:
|
|
112
|
+
throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );
|
|
113
113
|
}
|
|
114
114
|
if ( opts.series ) {
|
|
115
115
|
opts.limit = 1;
|
|
@@ -130,10 +130,10 @@ function factory( options, predicate ) {
|
|
|
130
130
|
*/
|
|
131
131
|
function noneByRightAsync( collection, done ) {
|
|
132
132
|
if ( !isCollection( collection ) ) {
|
|
133
|
-
throw new TypeError( 'invalid argument. First argument must be a collection. Value:
|
|
133
|
+
throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) );
|
|
134
134
|
}
|
|
135
135
|
if ( !isFunction( done ) ) {
|
|
136
|
-
throw new TypeError( 'invalid argument. Last argument must be a function. Value:
|
|
136
|
+
throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) );
|
|
137
137
|
}
|
|
138
138
|
return limit( collection, opts, f, clbk );
|
|
139
139
|
|
package/lib/index.js
CHANGED
|
@@ -63,15 +63,15 @@
|
|
|
63
63
|
// MODULES //
|
|
64
64
|
|
|
65
65
|
var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
|
|
66
|
-
var
|
|
66
|
+
var main = require( './main.js' );
|
|
67
67
|
var factory = require( './factory.js' );
|
|
68
68
|
|
|
69
69
|
|
|
70
70
|
// MAIN //
|
|
71
71
|
|
|
72
|
-
setReadOnly(
|
|
72
|
+
setReadOnly( main, 'factory', factory );
|
|
73
73
|
|
|
74
74
|
|
|
75
75
|
// EXPORTS //
|
|
76
76
|
|
|
77
|
-
module.exports =
|
|
77
|
+
module.exports = main;
|
|
@@ -33,7 +33,6 @@ var factory = require( './factory.js' );
|
|
|
33
33
|
* - If a predicate function calls the provided callback with a truthy error argument, the function suspends execution and immediately calls the `done` callback for subsequent error handling.
|
|
34
34
|
* - This function does **not** guarantee that execution is asynchronous. To do so, wrap the `done` callback in a function which either executes at the end of the current stack (e.g., `nextTick`) or during a subsequent turn of the event loop (e.g., `setImmediate`, `setTimeout`).
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
36
|
* @param {Collection} collection - input collection
|
|
38
37
|
* @param {Options} [options] - function options
|
|
39
38
|
* @param {*} [options.thisArg] - execution context
|
package/lib/validate.js
CHANGED
|
@@ -24,6 +24,7 @@ var isObject = require( '@stdlib/assert-is-plain-object' );
|
|
|
24
24
|
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
|
|
25
25
|
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
|
|
26
26
|
var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive;
|
|
27
|
+
var format = require( '@stdlib/string-format' );
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
// MAIN //
|
|
@@ -53,7 +54,7 @@ var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimit
|
|
|
53
54
|
*/
|
|
54
55
|
function validate( opts, options ) {
|
|
55
56
|
if ( !isObject( options ) ) {
|
|
56
|
-
return new TypeError( 'invalid argument. Options must be an object. Value:
|
|
57
|
+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
57
58
|
}
|
|
58
59
|
if ( hasOwnProp( options, 'thisArg' ) ) {
|
|
59
60
|
opts.thisArg = options.thisArg;
|
|
@@ -61,13 +62,13 @@ function validate( opts, options ) {
|
|
|
61
62
|
if ( hasOwnProp( options, 'series' ) ) {
|
|
62
63
|
opts.series = options.series;
|
|
63
64
|
if ( !isBoolean( opts.series ) ) {
|
|
64
|
-
return new TypeError( 'invalid option. `
|
|
65
|
+
return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) );
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
if ( hasOwnProp( options, 'limit' ) ) {
|
|
68
69
|
opts.limit = options.limit;
|
|
69
70
|
if ( !isPositiveInteger( opts.limit ) ) {
|
|
70
|
-
return new TypeError( 'invalid option. `
|
|
71
|
+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) );
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/utils-async-none-by-right",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Test whether all elements in a collection fail a test implemented by a predicate function, iterating from right to left.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -37,24 +37,27 @@
|
|
|
37
37
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@stdlib/assert-has-own-property": "^0.
|
|
41
|
-
"@stdlib/assert-is-boolean": "^0.0
|
|
42
|
-
"@stdlib/assert-is-collection": "^0.0
|
|
43
|
-
"@stdlib/assert-is-function": "^0.0
|
|
44
|
-
"@stdlib/assert-is-plain-object": "^0.0
|
|
45
|
-
"@stdlib/assert-is-positive-integer": "^0.0
|
|
46
|
-
"@stdlib/constants-float64-pinf": "^0.0
|
|
47
|
-
"@stdlib/
|
|
48
|
-
"@stdlib/
|
|
49
|
-
"
|
|
40
|
+
"@stdlib/assert-has-own-property": "^0.1.1",
|
|
41
|
+
"@stdlib/assert-is-boolean": "^0.2.0",
|
|
42
|
+
"@stdlib/assert-is-collection": "^0.2.0",
|
|
43
|
+
"@stdlib/assert-is-function": "^0.2.0",
|
|
44
|
+
"@stdlib/assert-is-plain-object": "^0.2.0",
|
|
45
|
+
"@stdlib/assert-is-positive-integer": "^0.2.0",
|
|
46
|
+
"@stdlib/constants-float64-pinf": "^0.2.0",
|
|
47
|
+
"@stdlib/string-format": "^0.2.0",
|
|
48
|
+
"@stdlib/types": "^0.3.1",
|
|
49
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.0",
|
|
50
|
+
"debug": "^2.6.9",
|
|
51
|
+
"@stdlib/error-tools-fmtprodmsg": "^0.1.1"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
|
-
"@stdlib/
|
|
53
|
-
"@stdlib/
|
|
54
|
-
"@stdlib/utils-noop": "^0.0.x",
|
|
54
|
+
"@stdlib/fs-read-file": "^0.1.1",
|
|
55
|
+
"@stdlib/utils-noop": "^0.2.0",
|
|
55
56
|
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
56
57
|
"istanbul": "^0.4.1",
|
|
57
|
-
"tap-
|
|
58
|
+
"tap-min": "git+https://github.com/Planeshifter/tap-min.git",
|
|
59
|
+
"@stdlib/bench-harness": "^0.1.2",
|
|
60
|
+
"@stdlib/bench": "^0.3.1"
|
|
58
61
|
},
|
|
59
62
|
"engines": {
|
|
60
63
|
"node": ">=0.10.0",
|
|
@@ -95,7 +98,7 @@
|
|
|
95
98
|
"validate"
|
|
96
99
|
],
|
|
97
100
|
"funding": {
|
|
98
|
-
"type": "
|
|
99
|
-
"url": "https://
|
|
101
|
+
"type": "opencollective",
|
|
102
|
+
"url": "https://opencollective.com/stdlib"
|
|
100
103
|
}
|
|
101
104
|
}
|
package/docs/repl.txt
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
{{alias}}( collection, [options,] predicate, done )
|
|
3
|
-
Tests whether all elements in a collection fail a test implemented by a
|
|
4
|
-
predicate function, iterating from right to left.
|
|
5
|
-
|
|
6
|
-
When invoked, the predicate function is provided a maximum of four
|
|
7
|
-
arguments:
|
|
8
|
-
|
|
9
|
-
- `value`: collection value
|
|
10
|
-
- `index`: collection index
|
|
11
|
-
- `collection`: the input collection
|
|
12
|
-
- `next`: a callback to be invoked after processing a collection `value`
|
|
13
|
-
|
|
14
|
-
The actual number of provided arguments depends on function length. If the
|
|
15
|
-
predicate function accepts two arguments, the predicate function is
|
|
16
|
-
provided:
|
|
17
|
-
|
|
18
|
-
- `value`
|
|
19
|
-
- `next`
|
|
20
|
-
|
|
21
|
-
If the predicate function accepts three arguments, the predicate function is
|
|
22
|
-
provided:
|
|
23
|
-
|
|
24
|
-
- `value`
|
|
25
|
-
- `index`
|
|
26
|
-
- `next`
|
|
27
|
-
|
|
28
|
-
For every other predicate function signature, the predicate function is
|
|
29
|
-
provided all four arguments.
|
|
30
|
-
|
|
31
|
-
The `next` callback takes two arguments:
|
|
32
|
-
|
|
33
|
-
- `error`: error argument
|
|
34
|
-
- `result`: test result
|
|
35
|
-
|
|
36
|
-
If a provided function calls the `next` callback with a truthy `error`
|
|
37
|
-
argument, the function suspends execution and immediately calls the `done`
|
|
38
|
-
callback for subsequent `error` handling.
|
|
39
|
-
|
|
40
|
-
The function immediately returns upon encountering a truthy `result` value
|
|
41
|
-
and calls the `done` callback with `null` as the first argument and `false`
|
|
42
|
-
as the second argument.
|
|
43
|
-
|
|
44
|
-
If all elements fail, the function calls the `done` callback with `null` as
|
|
45
|
-
the first argument and `true` as the second argument.
|
|
46
|
-
|
|
47
|
-
Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony,
|
|
48
|
-
wrap the `done` callback in a function which either executes at the end of
|
|
49
|
-
the current stack (e.g., `nextTick`) or during a subsequent turn of the
|
|
50
|
-
event loop (e.g., `setImmediate`, `setTimeout`).
|
|
51
|
-
|
|
52
|
-
The function does not support dynamic collection resizing.
|
|
53
|
-
|
|
54
|
-
The function does not skip `undefined` elements.
|
|
55
|
-
|
|
56
|
-
Parameters
|
|
57
|
-
----------
|
|
58
|
-
collection: Array|TypedArray|Object
|
|
59
|
-
Input collection over which to iterate. If provided an object, the
|
|
60
|
-
object must be array-like (excluding strings and functions).
|
|
61
|
-
|
|
62
|
-
options: Object (optional)
|
|
63
|
-
Function options.
|
|
64
|
-
|
|
65
|
-
options.limit: integer (optional)
|
|
66
|
-
Maximum number of pending invocations. Default: Infinity.
|
|
67
|
-
|
|
68
|
-
options.series: boolean (optional)
|
|
69
|
-
Boolean indicating whether to process each collection element
|
|
70
|
-
sequentially. Default: false.
|
|
71
|
-
|
|
72
|
-
options.thisArg: any (optional)
|
|
73
|
-
Execution context.
|
|
74
|
-
|
|
75
|
-
predicate: Function
|
|
76
|
-
The test function to invoke for each element in a collection.
|
|
77
|
-
|
|
78
|
-
done: Function
|
|
79
|
-
A callback invoked either upon processing all collection elements or
|
|
80
|
-
upon encountering an error.
|
|
81
|
-
|
|
82
|
-
Examples
|
|
83
|
-
--------
|
|
84
|
-
// Basic usage:
|
|
85
|
-
> function predicate( value, next ) {
|
|
86
|
-
... setTimeout( onTimeout, value );
|
|
87
|
-
... function onTimeout() {
|
|
88
|
-
... console.log( value );
|
|
89
|
-
... next( null, false );
|
|
90
|
-
... }
|
|
91
|
-
... };
|
|
92
|
-
> function done( error, bool ) {
|
|
93
|
-
... if ( error ) {
|
|
94
|
-
... throw error;
|
|
95
|
-
... }
|
|
96
|
-
... console.log( bool );
|
|
97
|
-
... };
|
|
98
|
-
> var arr = [ 1000, 2500, 3000 ];
|
|
99
|
-
> {{alias}}( arr, predicate, done )
|
|
100
|
-
1000
|
|
101
|
-
2500
|
|
102
|
-
3000
|
|
103
|
-
true
|
|
104
|
-
|
|
105
|
-
// Limit number of concurrent invocations:
|
|
106
|
-
> function predicate( value, next ) {
|
|
107
|
-
... setTimeout( onTimeout, value );
|
|
108
|
-
... function onTimeout() {
|
|
109
|
-
... console.log( value );
|
|
110
|
-
... next( null, false );
|
|
111
|
-
... }
|
|
112
|
-
... };
|
|
113
|
-
> function done( error, bool ) {
|
|
114
|
-
... if ( error ) {
|
|
115
|
-
... throw error;
|
|
116
|
-
... }
|
|
117
|
-
... console.log( bool );
|
|
118
|
-
... };
|
|
119
|
-
> var opts = { 'limit': 2 };
|
|
120
|
-
> var arr = [ 1000, 2500, 3000 ];
|
|
121
|
-
> {{alias}}( arr, opts, predicate, done )
|
|
122
|
-
2500
|
|
123
|
-
3000
|
|
124
|
-
1000
|
|
125
|
-
true
|
|
126
|
-
|
|
127
|
-
// Process sequentially:
|
|
128
|
-
> function predicate( value, next ) {
|
|
129
|
-
... setTimeout( onTimeout, value );
|
|
130
|
-
... function onTimeout() {
|
|
131
|
-
... console.log( value );
|
|
132
|
-
... next( null, false );
|
|
133
|
-
... }
|
|
134
|
-
... };
|
|
135
|
-
> function done( error, bool ) {
|
|
136
|
-
... if ( error ) {
|
|
137
|
-
... throw error;
|
|
138
|
-
... }
|
|
139
|
-
... console.log( bool );
|
|
140
|
-
... };
|
|
141
|
-
> var opts = { 'series': true };
|
|
142
|
-
> var arr = [ 1000, 2500, 3000 ];
|
|
143
|
-
> {{alias}}( arr, opts, predicate, done )
|
|
144
|
-
3000
|
|
145
|
-
2500
|
|
146
|
-
1000
|
|
147
|
-
true
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
{{alias}}.factory( [options,] predicate )
|
|
151
|
-
Returns a function which tests whether all elements in a collection fail a
|
|
152
|
-
test implemented by a predicate function, iterating from right to left.
|
|
153
|
-
|
|
154
|
-
Parameters
|
|
155
|
-
----------
|
|
156
|
-
options: Object (optional)
|
|
157
|
-
Function options.
|
|
158
|
-
|
|
159
|
-
options.limit: integer (optional)
|
|
160
|
-
Maximum number of pending invocations. Default: Infinity.
|
|
161
|
-
|
|
162
|
-
options.series: boolean (optional)
|
|
163
|
-
Boolean indicating whether to process each collection element
|
|
164
|
-
sequentially. Default: false.
|
|
165
|
-
|
|
166
|
-
options.thisArg: any (optional)
|
|
167
|
-
Execution context.
|
|
168
|
-
|
|
169
|
-
predicate: Function
|
|
170
|
-
The test function to invoke for each element in a collection.
|
|
171
|
-
|
|
172
|
-
Returns
|
|
173
|
-
-------
|
|
174
|
-
out: Function
|
|
175
|
-
A function which tests each element in a collection.
|
|
176
|
-
|
|
177
|
-
Examples
|
|
178
|
-
--------
|
|
179
|
-
> function predicate( value, next ) {
|
|
180
|
-
... setTimeout( onTimeout, value );
|
|
181
|
-
... function onTimeout() {
|
|
182
|
-
... console.log( value );
|
|
183
|
-
... next( null, false );
|
|
184
|
-
... }
|
|
185
|
-
... };
|
|
186
|
-
> var opts = { 'series': true };
|
|
187
|
-
> var f = {{alias}}.factory( opts, predicate );
|
|
188
|
-
> function done( error, bool ) {
|
|
189
|
-
... if ( error ) {
|
|
190
|
-
... throw error;
|
|
191
|
-
... }
|
|
192
|
-
... console.log( bool );
|
|
193
|
-
... };
|
|
194
|
-
> var arr = [ 1000, 2500, 3000 ];
|
|
195
|
-
> f( arr, done )
|
|
196
|
-
3000
|
|
197
|
-
2500
|
|
198
|
-
1000
|
|
199
|
-
true
|
|
200
|
-
> arr = [ 1000, 1500, 2000 ];
|
|
201
|
-
> f( arr, done )
|
|
202
|
-
2000
|
|
203
|
-
1500
|
|
204
|
-
1000
|
|
205
|
-
true
|
|
206
|
-
|
|
207
|
-
See Also
|
|
208
|
-
--------
|
|
209
|
-
|