@stdlib/utils-async-some-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.
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/validate.js", "../lib/limit.js", "../lib/factory.js", "../lib/main.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isObject = require( '@stdlib/assert-is-plain-object' );\nvar hasOwnProp = require( '@stdlib/assert-has-own-property' );\nvar isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;\nvar isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive;\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Validates function options.\n*\n* @private\n* @param {Object} opts - destination object\n* @param {Options} options - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection\n* @returns {(Error|null)} null or an error object\n*\n* @example\n* var opts = {};\n* var options = {\n* 'thisArg': {},\n* 'series': false,\n* 'limit': 10\n* };\n* var err = validate( opts, options );\n* if ( err ) {\n* throw err;\n* }\n*/\nfunction validate( opts, options ) {\n\tif ( !isObject( options ) ) {\n\t\treturn new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );\n\t}\n\tif ( hasOwnProp( options, 'thisArg' ) ) {\n\t\topts.thisArg = options.thisArg;\n\t}\n\tif ( hasOwnProp( options, 'series' ) ) {\n\t\topts.series = options.series;\n\t\tif ( !isBoolean( opts.series ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'series', opts.series ) );\n\t\t}\n\t}\n\tif ( hasOwnProp( options, 'limit' ) ) {\n\t\topts.limit = options.limit;\n\t\tif ( !isPositiveInteger( opts.limit ) ) {\n\t\t\treturn new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'limit', opts.limit ) );\n\t\t}\n\t}\n\treturn null;\n}\n\n\n// EXPORTS //\n\nmodule.exports = validate;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar logger = require( 'debug' );\n\n\n// VARIABLES //\n\nvar debug = logger( 'some-by-right-async:limit' );\n\n\n// MAIN //\n\n/**\n* Invokes a predicate function once for each element in a collection, limiting the number of concurrently pending functions and iterating from right to left.\n*\n* @private\n* @param {Collection} collection - input collection\n* @param {PositiveInteger} n - number of elements\n* @param {Options} opts - function options\n* @param {*} [opts.thisArg] - execution context\n* @param {PositiveInteger} [opts.limit] - maximum number of pending function invocations\n* @param {Function} predicate - predicate function\n* @param {Callback} done - function to invoke upon completion or upon encountering an error\n* @returns {void}\n*/\nfunction limit( collection, n, opts, predicate, done ) {\n\tvar count;\n\tvar flg;\n\tvar lim;\n\tvar len;\n\tvar idx;\n\tvar cnt;\n\tvar i;\n\n\tlen = collection.length;\n\tdebug( 'Collection length: %d', len );\n\n\tif ( len === 0 ) {\n\t\tdebug( 'Finished processing a collection.' );\n\t\treturn done( null, false );\n\t}\n\tif ( len < opts.limit ) {\n\t\tlim = len;\n\t} else {\n\t\tlim = opts.limit;\n\t}\n\tdebug( 'Concurrency limit: %d', lim );\n\tdebug( 'Number of arguments: %d', predicate.length );\n\n\tcount = 0; // processed element count\n\tidx = len;\n\tcnt = 0; // success count\n\tfor ( i = 0; i < lim; i++ ) {\n\t\t// This guard is necessary to protect against synchronous functions which exhaust all collection elements...\n\t\tif ( idx > 0 ) {\n\t\t\tnext(); // eslint-disable-line node/callback-return\n\t\t}\n\t}\n\n\t/**\n\t* Callback to invoke a provided function for the next element in a collection.\n\t*\n\t* @private\n\t*/\n\tfunction next() {\n\t\tidx -= 1;\n\t\tdebug( 'Collection element %d: %s.', idx, JSON.stringify( collection[ idx ] ) );\n\t\tif ( predicate.length === 2 ) {\n\t\t\tpredicate.call( opts.thisArg, collection[ idx ], clbk );\n\t\t} else if ( predicate.length === 3 ) {\n\t\t\tpredicate.call( opts.thisArg, collection[ idx ], idx, clbk );\n\t\t} else {\n\t\t\tpredicate.call( opts.thisArg, collection[ idx ], idx, collection, clbk ); // eslint-disable-line max-len\n\t\t}\n\t}\n\n\t/**\n\t* Callback invoked once a provided function finishes processing a collection element.\n\t*\n\t* @private\n\t* @param {*} [error] - error\n\t* @param {*} [result] - test result\n\t* @returns {void}\n\t*/\n\tfunction clbk( error, result ) {\n\t\tif ( flg ) {\n\t\t\t// Prevent further processing of collection elements:\n\t\t\treturn;\n\t\t}\n\t\tif ( error ) {\n\t\t\tflg = true;\n\t\t\tdebug( 'Encountered an error: %s', error.message );\n\t\t\treturn done( error );\n\t\t}\n\t\tcount += 1;\n\t\tdebug( 'Processed %d of %d collection elements.', count, len );\n\n\t\tdebug( 'Test result: %s', !!result );\n\t\tif ( result && !flg ) {\n\t\t\tcnt += 1;\n\t\t\tif ( cnt === n ) {\n\t\t\t\tflg = true;\n\t\t\t\tdebug( 'Finished processing a collection.' );\n\t\t\t\treturn done( null, true );\n\t\t\t}\n\t\t}\n\t\tif ( idx > 0 ) {\n\t\t\treturn next();\n\t\t}\n\t\tif ( count === len ) {\n\t\t\tdebug( 'Finished processing a collection.' );\n\t\t\treturn done( null, false );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = limit;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive;\nvar isCollection = require( '@stdlib/assert-is-collection' );\nvar format = require( '@stdlib/string-format' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar validate = require( './validate.js' );\nvar limit = require( './limit.js' );\n\n\n// MAIN //\n\n/**\n* Returns a function for testing whether a collection contains at least `n` elements which pass a test implemented by a predicate function, iterating from right to left.\n*\n* ## Notes\n*\n* - 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.\n* - 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`).\n*\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection\n* @param {Function} predicate - predicate function to invoke for each element in a collection\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {TypeError} last argument must be a function\n* @returns {Function} function which invokes the predicate function once for each element in a collection\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function predicate( file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, false );\n* }\n* next( null, true );\n* }\n* }\n*\n* var opts = {\n* 'series': true\n* };\n*\n* // Create a `someByRightAsync` function which invokes the predicate function for each collection element sequentially:\n* var someByRightAsync = factory( opts, predicate );\n*\n* // Create a collection over which to iterate:\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* // Define a callback which handles results:\n* function done( error, bool ) {\n* if ( error ) {\n* throw error;\n* }\n* if ( bool ) {\n* console.log( 'Successfully read some files.' );\n* } else {\n* console.log( 'Unable to read some files.' );\n* }\n* }\n*\n* // Try to read each element in `files`:\n* someByRightAsync( files, 2, done );\n*/\nfunction factory( options, predicate ) {\n\tvar opts;\n\tvar err;\n\tvar f;\n\n\topts = {};\n\tif ( arguments.length > 1 ) {\n\t\terr = validate( opts, options );\n\t\tif ( err ) {\n\t\t\tthrow err;\n\t\t}\n\t\tf = predicate;\n\t} else {\n\t\tf = options;\n\t}\n\tif ( !isFunction( f ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );\n\t}\n\tif ( opts.series ) {\n\t\topts.limit = 1;\n\t} else if ( !opts.limit ) {\n\t\topts.limit = PINF;\n\t}\n\treturn someByRightAsync;\n\n\t/**\n\t* Invokes a predicate function for each element in a collection, iterating from right to left.\n\t*\n\t* @private\n\t* @param {Collection} collection - input collection\n\t* @param {PositiveInteger} n - number of elements\n\t* @param {Callback} done - function to invoke upon completion\n\t* @throws {TypeError} first argument must be a collection\n\t* @throws {TypeError} second argument must be a positive integer\n\t* @throws {TypeError} last argument must be a function\n\t* @returns {void}\n\t*/\n\tfunction someByRightAsync( collection, n, done ) {\n\t\tif ( !isCollection( collection ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) );\n\t\t}\n\t\tif ( !isPositiveInteger( n ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', n ) );\n\t\t}\n\t\tif ( !isFunction( done ) ) {\n\t\t\tthrow new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) );\n\t\t}\n\t\treturn limit( collection, n, opts, f, clbk );\n\n\t\t/**\n\t\t* Callback invoked upon completion.\n\t\t*\n\t\t* @private\n\t\t* @param {*} [error] - error\n\t\t* @param {boolean} bool - test result\n\t\t* @returns {void}\n\t\t*/\n\t\tfunction clbk( error, bool ) {\n\t\t\tif ( error ) {\n\t\t\t\treturn done( error, false );\n\t\t\t}\n\t\t\tdone( null, bool );\n\t\t}\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\n/**\n* Tests whether a collection contains at least `n` elements which pass a test implemented by a predicate function, iterating from right to left.\n*\n* ## Notes\n*\n* - 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.\n* - 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`).\n*\n* @param {Collection} collection - input collection\n* @param {PositiveInteger} n - number of elements\n* @param {Options} [options] - function options\n* @param {*} [options.thisArg] - execution context\n* @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time\n* @param {boolean} [options.series=false] - boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection\n* @param {Function} predicate - predicate function to invoke for each element in a collection\n* @param {Callback} done - function to invoke upon completion\n* @throws {TypeError} first argument must be a collection\n* @throws {TypeError} second argument must be a positive integer\n* @throws {TypeError} options argument must be an object\n* @throws {TypeError} must provide valid options\n* @throws {TypeError} second-to-last argument must be a function\n* @throws {TypeError} last argument must be a function\n* @returns {void}\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n*\n* function done( error, bool ) {\n* if ( error ) {\n* throw error;\n* }\n* if ( bool ) {\n* console.log( 'Successfully read some files.' );\n* } else {\n* console.log( 'Unable to read some files.' );\n* }\n* }\n*\n* function predicate( file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, false );\n* }\n* next( null, true );\n* }\n* }\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* someByRightAsync( files, 2, predicate, done );\n*/\nfunction someByRightAsync( collection, n, options, predicate, done ) {\n\tif ( arguments.length < 5 ) {\n\t\treturn factory( options )( collection, n, predicate );\n\t}\n\tfactory( options, predicate )( collection, n, done );\n}\n\n\n// EXPORTS //\n\nmodule.exports = someByRightAsync;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Test whether a collection contains at least `n` elements which pass a test implemented by a predicate function, iterating from right to left.\n*\n* @module @stdlib/utils-async-some-by-right\n*\n* @example\n* var readFile = require( '@stdlib/fs-read-file' );\n* var someByRightAsync = require( '@stdlib/utils-async-some-by-right' );\n*\n* var files = [\n* './beep.js',\n* './boop.js'\n* ];\n*\n* function done( error, bool ) {\n* if ( error ) {\n* throw error;\n* }\n* if ( bool ) {\n* console.log( 'Successfully read some files.' );\n* } else {\n* console.log( 'Unable to read some files.' );\n* }\n* }\n*\n* function predicate( file, next ) {\n* var opts = {\n* 'encoding': 'utf8'\n* };\n* readFile( file, opts, onFile );\n*\n* function onFile( error ) {\n* if ( error ) {\n* return next( null, false );\n* }\n* next( null, true );\n* }\n* }\n*\n* someByRightAsync( files, 2, predicate, done );\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAW,QAAS,gCAAiC,EACrDC,EAAa,QAAS,iCAAkC,EACxDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAoB,QAAS,oCAAqC,EAAE,YACpEC,EAAS,QAAS,uBAAwB,EA4B9C,SAASC,EAAUC,EAAMC,EAAU,CAClC,OAAMP,EAAUO,CAAQ,GAGnBN,EAAYM,EAAS,SAAU,IACnCD,EAAK,QAAUC,EAAQ,SAEnBN,EAAYM,EAAS,QAAS,IAClCD,EAAK,OAASC,EAAQ,OACjB,CAACL,EAAWI,EAAK,MAAO,GACrB,IAAI,UAAWF,EAAQ,+DAAgE,SAAUE,EAAK,MAAO,CAAE,EAGnHL,EAAYM,EAAS,OAAQ,IACjCD,EAAK,MAAQC,EAAQ,MAChB,CAACJ,EAAmBG,EAAK,KAAM,GAC5B,IAAI,UAAWF,EAAQ,wEAAyE,QAASE,EAAK,KAAM,CAAE,EAGxH,MAjBC,IAAI,UAAWF,EAAQ,qEAAsEG,CAAQ,CAAE,CAkBhH,CAKAR,EAAO,QAAUM,IC/EjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,OAAQ,EAK1BC,EAAQD,EAAQ,2BAA4B,EAkBhD,SAASE,EAAOC,EAAYC,EAAGC,EAAMC,EAAWC,EAAO,CACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAH,EAAMR,EAAW,OACjBF,EAAO,wBAAyBU,CAAI,EAE/BA,IAAQ,EACZ,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAM,EAAM,EAa1B,IAXKI,EAAMN,EAAK,MACfK,EAAMC,EAEND,EAAML,EAAK,MAEZJ,EAAO,wBAAyBS,CAAI,EACpCT,EAAO,0BAA2BK,EAAU,MAAO,EAEnDE,EAAQ,EACRI,EAAMD,EACNE,EAAM,EACAC,EAAI,EAAGA,EAAIJ,EAAKI,IAEhBF,EAAM,GACVG,EAAK,EASP,SAASA,GAAO,CACfH,GAAO,EACPX,EAAO,6BAA8BW,EAAK,KAAK,UAAWT,EAAYS,CAAI,CAAE,CAAE,EACzEN,EAAU,SAAW,EACzBA,EAAU,KAAMD,EAAK,QAASF,EAAYS,CAAI,EAAGI,CAAK,EAC3CV,EAAU,SAAW,EAChCA,EAAU,KAAMD,EAAK,QAASF,EAAYS,CAAI,EAAGA,EAAKI,CAAK,EAE3DV,EAAU,KAAMD,EAAK,QAASF,EAAYS,CAAI,EAAGA,EAAKT,EAAYa,CAAK,CAEzE,CAUA,SAASA,EAAMC,EAAOC,EAAS,CAC9B,GAAK,CAAAT,EAIL,IAAKQ,EACJ,OAAAR,EAAM,GACNR,EAAO,2BAA4BgB,EAAM,OAAQ,EAC1CV,EAAMU,CAAM,EAMpB,GAJAT,GAAS,EACTP,EAAO,0CAA2CO,EAAOG,CAAI,EAE7DV,EAAO,kBAAmB,CAAC,CAACiB,CAAO,EAC9BA,GAAU,CAACT,IACfI,GAAO,EACFA,IAAQT,GACZ,OAAAK,EAAM,GACNR,EAAO,mCAAoC,EACpCM,EAAM,KAAM,EAAK,EAG1B,GAAKK,EAAM,EACV,OAAOG,EAAK,EAEb,GAAKP,IAAUG,EACd,OAAAV,EAAO,mCAAoC,EACpCM,EAAM,KAAM,EAAM,EAE3B,CACD,CAKAR,EAAO,QAAUG,IC3IjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,4BAA6B,EACnDC,EAAoB,QAAS,oCAAqC,EAAE,YACpEC,EAAe,QAAS,8BAA+B,EACvDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,gCAAiC,EACjDC,EAAW,IACXC,EAAQ,IAoEZ,SAASC,EAASC,EAASC,EAAY,CACtC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAO,CAAC,EACH,UAAU,OAAS,EAAI,CAE3B,GADAC,EAAMN,EAAUK,EAAMF,CAAQ,EACzBG,EACJ,MAAMA,EAEPC,EAAIH,CACL,MACCG,EAAIJ,EAEL,GAAK,CAACR,EAAYY,CAAE,EACnB,MAAM,IAAI,UAAWT,EAAQ,mEAAoES,CAAE,CAAE,EAEtG,OAAKF,EAAK,OACTA,EAAK,MAAQ,EACDA,EAAK,QACjBA,EAAK,MAAQN,GAEPS,EAcP,SAASA,EAAkBC,EAAYC,EAAGC,EAAO,CAChD,GAAK,CAACd,EAAcY,CAAW,EAC9B,MAAM,IAAI,UAAWX,EAAQ,sEAAuEW,CAAW,CAAE,EAElH,GAAK,CAACb,EAAmBc,CAAE,EAC1B,MAAM,IAAI,UAAWZ,EAAQ,6EAA8EY,CAAE,CAAE,EAEhH,GAAK,CAACf,EAAYgB,CAAK,EACtB,MAAM,IAAI,UAAWb,EAAQ,mEAAoEa,CAAK,CAAE,EAEzG,OAAOV,EAAOQ,EAAYC,EAAGL,EAAME,EAAGK,CAAK,EAU3C,SAASA,EAAMC,EAAOC,EAAO,CAC5B,GAAKD,EACJ,OAAOF,EAAME,EAAO,EAAM,EAE3BF,EAAM,KAAMG,CAAK,CAClB,CACD,CACD,CAKApB,EAAO,QAAUQ,ICrKjB,IAAAa,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,IAgEd,SAASC,EAAkBC,EAAYC,EAAGC,EAASC,EAAWC,EAAO,CACpE,GAAK,UAAU,OAAS,EACvB,OAAON,EAASI,CAAQ,EAAGF,EAAYC,EAAGE,CAAU,EAErDL,EAASI,EAASC,CAAU,EAAGH,EAAYC,EAAGG,CAAK,CACpD,CAKAP,EAAO,QAAUE,IChCjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
6
+ "names": ["require_validate", "__commonJSMin", "exports", "module", "isObject", "hasOwnProp", "isBoolean", "isPositiveInteger", "format", "validate", "opts", "options", "require_limit", "__commonJSMin", "exports", "module", "logger", "debug", "limit", "collection", "n", "opts", "predicate", "done", "count", "flg", "lim", "len", "idx", "cnt", "i", "next", "clbk", "error", "result", "require_factory", "__commonJSMin", "exports", "module", "isFunction", "isPositiveInteger", "isCollection", "format", "PINF", "validate", "limit", "factory", "options", "predicate", "opts", "err", "f", "someByRightAsync", "collection", "n", "done", "clbk", "error", "bool", "require_main", "__commonJSMin", "exports", "module", "factory", "someByRightAsync", "collection", "n", "options", "predicate", "done", "setReadOnly", "main", "factory"]
7
+ }
@@ -16,30 +16,30 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- // TypeScript Version: 2.0
19
+ // TypeScript Version: 4.1
20
20
 
21
21
  /// <reference types="@stdlib/types"/>
22
22
 
23
- import { Collection } from '@stdlib/types/object';
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
  */
32
32
  limit?: number;
33
33
 
34
34
  /**
35
- * Boolean indicating whether to wait for a previous invocation to complete before invoking a provided function for the next element in a collection (default: false).
35
+ * Boolean indicating whether to sequentially invoke the `predicate` function for each `collection` element. If `true`, the function sets `options.limit=1`.
36
36
  */
37
37
  series?: boolean;
38
38
 
39
39
  /**
40
40
  * Execution context.
41
41
  */
42
- thisArg?: any;
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: any, next: Callback ) => void;
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: any, index: number, next: Callback ) => void;
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: any, index: number, collection: Collection, next: Callback ) => void; // tslint-disable-line max-line-length
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,16 +105,16 @@ 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 at least one element in a collection passes a test implemented by a predicate function.
111
+ * Tests whether at least `n` elements in a collection pass a test implemented by a predicate function.
112
112
  *
113
113
  * @param collection - input collection
114
114
  * @param n - number of elements
115
115
  * @param done - function to invoke upon completion
116
116
  */
117
- type FactoryFunction = ( collection: Collection, n: number, done: Callback ) => void; // tslint-disable-line max-line-length
117
+ type FactoryFunction<T> = ( collection: Collection<T>, n: number, done: Callback ) => void;
118
118
 
119
119
  /**
120
120
  * Interface for `someByRightAsync`.
@@ -128,7 +128,6 @@ interface SomeByRightAsync {
128
128
  * - 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.
129
129
  * - 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`).
130
130
  *
131
- *
132
131
  * @param collection - input collection
133
132
  * @param n - number of elements
134
133
  * @param options - function options
@@ -141,7 +140,7 @@ interface SomeByRightAsync {
141
140
  * @throws must provide valid options
142
141
  *
143
142
  * @example
144
- * var readFile = require( `@stdlib/fs/read-file` );
143
+ * var readFile = require( '@stdlib/fs-read-file' );
145
144
  *
146
145
  * function done( error, bool ) {
147
146
  * if ( error ) {
@@ -175,7 +174,7 @@ interface SomeByRightAsync {
175
174
  *
176
175
  * someByRightAsync( files, 2, predicate, done );
177
176
  */
178
- ( collection: Collection, n: number, options: Options, predicate: Predicate, done: Callback ): void; // tslint-disable-line max-line-length
177
+ <T = unknown, V = unknown>( collection: Collection<T>, n: number, options: Options<T, V>, predicate: Predicate<T, V>, done: Callback ): void;
179
178
 
180
179
  /**
181
180
  * Tests whether a collection contains at least `n` elements which pass a test implemented by a predicate function, iterating from right to left.
@@ -185,7 +184,6 @@ interface SomeByRightAsync {
185
184
  * - 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.
186
185
  * - 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`).
187
186
  *
188
- *
189
187
  * @param collection - input collection
190
188
  * @param n - number of elements
191
189
  * @param predicate - predicate function to invoke for each element in a collection
@@ -194,7 +192,7 @@ interface SomeByRightAsync {
194
192
  * @throws must provide valid options
195
193
  *
196
194
  * @example
197
- * var readFile = require( `@stdlib/fs/read-file` );
195
+ * var readFile = require( '@stdlib/fs-read-file' );
198
196
  *
199
197
  * function done( error, bool ) {
200
198
  * if ( error ) {
@@ -228,7 +226,7 @@ interface SomeByRightAsync {
228
226
  *
229
227
  * someByRightAsync( files, 2, predicate, done );
230
228
  */
231
- ( collection: Collection, n: number, predicate: Predicate, done: Callback ): void; // tslint-disable-line max-line-length
229
+ <T = unknown, V = unknown>( collection: Collection<T>, n: number, predicate: Predicate<T, V>, done: Callback ): void;
232
230
 
233
231
  /**
234
232
  * Returns a function for testing whether a collection contains at least `n` elements which pass a test implemented by a predicate function, iterating from right to left.
@@ -238,7 +236,6 @@ interface SomeByRightAsync {
238
236
  * - 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.
239
237
  * - 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`).
240
238
  *
241
- *
242
239
  * @param options - function options
243
240
  * @param options.thisArg - execution context
244
241
  * @param options.limit - maximum number of pending invocations at any one time
@@ -248,7 +245,7 @@ interface SomeByRightAsync {
248
245
  * @returns function which invokes the predicate function once for each element in a collection
249
246
  *
250
247
  * @example
251
- * var readFile = require( `@stdlib/fs/read-file` );
248
+ * var readFile = require( '@stdlib/fs-read-file' );
252
249
  *
253
250
  * function predicate( file, next ) {
254
251
  * var opts = {
@@ -292,7 +289,7 @@ interface SomeByRightAsync {
292
289
  * // Try to read each element in `files`:
293
290
  * someByRightAsync( files, 2, done );
294
291
  */
295
- factory( options: Options, predicate: Predicate ): FactoryFunction;
292
+ factory<T = unknown, V = unknown>( options: Options<T, V>, predicate: Predicate<T, V> ): FactoryFunction<T>;
296
293
 
297
294
  /**
298
295
  * Returns a function for testing whether a collection contains at least `n` elements which pass a test implemented by a predicate function, iterating from right to left.
@@ -302,13 +299,12 @@ interface SomeByRightAsync {
302
299
  * - 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.
303
300
  * - 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`).
304
301
  *
305
- *
306
302
  * @param predicate - predicate function to invoke for each element in a collection
307
303
  * @throws must provide valid options
308
304
  * @returns function which invokes the predicate function once for each element in a collection
309
305
  *
310
306
  * @example
311
- * var readFile = require( `@stdlib/fs/read-file` );
307
+ * var readFile = require( '@stdlib/fs-read-file' );
312
308
  *
313
309
  * function predicate( file, next ) {
314
310
  * var opts = {
@@ -352,7 +348,7 @@ interface SomeByRightAsync {
352
348
  * // Try to read each element in `files`:
353
349
  * someByRightAsync( files, 2, done );
354
350
  */
355
- factory( predicate: Predicate ): FactoryFunction;
351
+ factory<T = unknown, V = unknown>( predicate: Predicate<T, V> ): FactoryFunction<T>;
356
352
  }
357
353
 
358
354
  /**
@@ -363,7 +359,6 @@ interface SomeByRightAsync {
363
359
  * - 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.
364
360
  * - 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`).
365
361
  *
366
- *
367
362
  * @param collection - input collection
368
363
  * @param n - number of elements
369
364
  * @param options - function options
@@ -376,7 +371,7 @@ interface SomeByRightAsync {
376
371
  * @throws must provide valid options
377
372
  *
378
373
  * @example
379
- * var readFile = require( `@stdlib/fs/read-file` );
374
+ * var readFile = require( '@stdlib/fs-read-file' );
380
375
  *
381
376
  * function done( error, bool ) {
382
377
  * if ( error ) {
package/lib/factory.js CHANGED
@@ -23,6 +23,7 @@
23
23
  var isFunction = require( '@stdlib/assert-is-function' );
24
24
  var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive;
25
25
  var isCollection = require( '@stdlib/assert-is-collection' );
26
+ var format = require( '@stdlib/string-format' );
26
27
  var PINF = require( '@stdlib/constants-float64-pinf' );
27
28
  var validate = require( './validate.js' );
28
29
  var limit = require( './limit.js' );
@@ -38,7 +39,6 @@ var limit = require( './limit.js' );
38
39
  * - 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.
39
40
  * - 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`).
40
41
  *
41
- *
42
42
  * @param {Options} [options] - function options
43
43
  * @param {*} [options.thisArg] - execution context
44
44
  * @param {PositiveInteger} [options.limit] - maximum number of pending invocations at any one time
@@ -110,7 +110,7 @@ function factory( options, predicate ) {
110
110
  f = options;
111
111
  }
112
112
  if ( !isFunction( f ) ) {
113
- throw new TypeError( 'invalid argument. Last argument must be a function. Value: `'+f+'`.' );
113
+ throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', f ) );
114
114
  }
115
115
  if ( opts.series ) {
116
116
  opts.limit = 1;
@@ -133,13 +133,13 @@ function factory( options, predicate ) {
133
133
  */
134
134
  function someByRightAsync( collection, n, done ) {
135
135
  if ( !isCollection( collection ) ) {
136
- throw new TypeError( 'invalid argument. First argument must be a collection. Value: `'+collection+'.`' );
136
+ throw new TypeError( format( 'invalid argument. First argument must be a collection. Value: `%s`.', collection ) );
137
137
  }
138
138
  if ( !isPositiveInteger( n ) ) {
139
- throw new TypeError( 'invalid argument. Second argument must be a positive integer. Value: `'+n+'`.' );
139
+ throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', n ) );
140
140
  }
141
141
  if ( !isFunction( done ) ) {
142
- throw new TypeError( 'invalid argument. Last argument must be a function. Value: `'+done+'`.' );
142
+ throw new TypeError( format( 'invalid argument. Last argument must be a function. Value: `%s`.', done ) );
143
143
  }
144
144
  return limit( collection, n, opts, f, clbk );
145
145
 
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 someByRightAsync = require( './some_by_right.js' );
66
+ var main = require( './main.js' );
67
67
  var factory = require( './factory.js' );
68
68
 
69
69
 
70
70
  // MAIN //
71
71
 
72
- setReadOnly( someByRightAsync, 'factory', factory );
72
+ setReadOnly( main, 'factory', factory );
73
73
 
74
74
 
75
75
  // EXPORTS //
76
76
 
77
- module.exports = someByRightAsync;
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 {PositiveInteger} n - number of elements
39
38
  * @param {Options} [options] - function options
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: `' + options + '`.' );
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. `series` option must be a boolean primitive. Option: `' + opts.series + '`.' );
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. `limit` option must be a positive integer. Option: `' + opts.limit + '`.' );
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-some-by-right",
3
- "version": "0.0.8",
3
+ "version": "0.2.0",
4
4
  "description": "Test whether a collection contains at least `n` elements which pass 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.0.x",
41
- "@stdlib/assert-is-boolean": "^0.0.x",
42
- "@stdlib/assert-is-collection": "^0.0.x",
43
- "@stdlib/assert-is-function": "^0.0.x",
44
- "@stdlib/assert-is-plain-object": "^0.0.x",
45
- "@stdlib/assert-is-positive-integer": "^0.0.x",
46
- "@stdlib/constants-float64-pinf": "^0.0.x",
47
- "@stdlib/types": "^0.0.x",
48
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x",
49
- "debug": "^2.6.9"
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/bench": "^0.0.x",
53
- "@stdlib/fs-read-file": "^0.0.x",
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-spec": "5.x.x"
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",
@@ -97,7 +100,7 @@
97
100
  "validate"
98
101
  ],
99
102
  "funding": {
100
- "type": "patreon",
101
- "url": "https://www.patreon.com/athan"
103
+ "type": "opencollective",
104
+ "url": "https://opencollective.com/stdlib"
102
105
  }
103
106
  }
package/docs/repl.txt DELETED
@@ -1,213 +0,0 @@
1
-
2
- {{alias}}( collection, n, [options,] predicate, done )
3
- Tests whether a collection contains at least `n` elements which pass a test
4
- implemented by a 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 receiving `n` non-falsy `result`
41
- values and calls the `done` callback with `null` as the first argument and
42
- `true` as the second argument.
43
-
44
- If all elements fail, the function calls the `done` callback with `null`
45
- as the first argument and `false` 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
- n: number
63
- Minimum number of successful elements.
64
-
65
- options: Object (optional)
66
- Function options.
67
-
68
- options.limit: integer (optional)
69
- Maximum number of pending invocations. Default: Infinity.
70
-
71
- options.series: boolean (optional)
72
- Boolean indicating whether to process each collection element
73
- sequentially. Default: false.
74
-
75
- options.thisArg: any (optional)
76
- Execution context.
77
-
78
- predicate: Function
79
- The test function to invoke for each element in a collection.
80
-
81
- done: Function
82
- A callback invoked either upon processing all collection elements or
83
- upon encountering an error.
84
-
85
- Examples
86
- --------
87
- // Basic usage:
88
- > function predicate( value, next ) {
89
- ... setTimeout( onTimeout, value );
90
- ... function onTimeout() {
91
- ... console.log( value );
92
- ... next( null, false );
93
- ... }
94
- ... };
95
- > function done( error, bool ) {
96
- ... if ( error ) {
97
- ... throw error;
98
- ... }
99
- ... console.log( bool );
100
- ... };
101
- > var arr = [ 1000, 2500, 3000 ];
102
- > {{alias}}( arr, 2, predicate, done )
103
- 1000
104
- 2500
105
- 3000
106
- false
107
-
108
- // Limit number of concurrent invocations:
109
- > function predicate( value, next ) {
110
- ... setTimeout( onTimeout, value );
111
- ... function onTimeout() {
112
- ... console.log( value );
113
- ... next( null, false );
114
- ... }
115
- ... };
116
- > function done( error, bool ) {
117
- ... if ( error ) {
118
- ... throw error;
119
- ... }
120
- ... console.log( bool );
121
- ... };
122
- > var opts = { 'limit': 2 };
123
- > var arr = [ 1000, 2500, 3000 ];
124
- > {{alias}}( arr, 2, opts, predicate, done )
125
- 2500
126
- 3000
127
- 1000
128
- false
129
-
130
- // Process sequentially:
131
- > function predicate( value, next ) {
132
- ... setTimeout( onTimeout, value );
133
- ... function onTimeout() {
134
- ... console.log( value );
135
- ... next( null, false );
136
- ... }
137
- ... };
138
- > function done( error, bool ) {
139
- ... if ( error ) {
140
- ... throw error;
141
- ... }
142
- ... console.log( bool );
143
- ... };
144
- > var opts = { 'series': true };
145
- > var arr = [ 1000, 2500, 3000 ];
146
- > {{alias}}( arr, 2, opts, predicate, done )
147
- 3000
148
- 2500
149
- 1000
150
- false
151
-
152
-
153
- {{alias}}.factory( [options,] predicate )
154
- Returns a function which tests whether a collection contains at least `n`
155
- elements which pass a test implemented by a predicate function, iterating
156
- from right to left.
157
-
158
- Parameters
159
- ----------
160
- options: Object (optional)
161
- Function options.
162
-
163
- options.limit: integer (optional)
164
- Maximum number of pending invocations. Default: Infinity.
165
-
166
- options.series: boolean (optional)
167
- Boolean indicating whether to process each collection element
168
- sequentially. Default: false.
169
-
170
- options.thisArg: any (optional)
171
- Execution context.
172
-
173
- predicate: Function
174
- The test function to invoke for each element in a collection.
175
-
176
- Returns
177
- -------
178
- out: Function
179
- A function which tests each element in a collection.
180
-
181
- Examples
182
- --------
183
- > function predicate( value, next ) {
184
- ... setTimeout( onTimeout, value );
185
- ... function onTimeout() {
186
- ... console.log( value );
187
- ... next( null, false );
188
- ... }
189
- ... };
190
- > var opts = { 'series': true };
191
- > var f = {{alias}}.factory( opts, predicate );
192
- > function done( error, bool ) {
193
- ... if ( error ) {
194
- ... throw error;
195
- ... }
196
- ... console.log( bool );
197
- ... };
198
- > var arr = [ 1000, 2500, 3000 ];
199
- > f( arr, 2, done )
200
- 3000
201
- 2500
202
- 1000
203
- false
204
- > arr = [ 1000, 1500, 2000 ];
205
- > f( arr, 2, done )
206
- 2000
207
- 1500
208
- 1000
209
- false
210
-
211
- See Also
212
- --------
213
-